Tell me how you can process the received response from the server and, depending on the response, redirect the user to the desired page. I can not figure out how to do it. In general, the essence is as follows: There is a html form.
<form name="codeForm" novalidate> <input name="code" type="text" placeholder="Enter your code" ng-model="confirm.code" required> <a href="/nextpage"><button ng-click="send()" ng-disabled="codeForm.$invalid">Next</button></a> </form>
When you click on a button, the data that was filled in the input is sent to the server:
angular .module('app') .factory('myFactory', myFactory); function myFactory($http, $q) { return { confirmPhoneNumber: function(){ var deferred = $q.defer(); $http({ url: "http://example:8080/mimimi/", method: "POST", data: data, }).success(function(data, status, headers, config){ deferred.resolve(data); console.log(data) }).error(function(data, status, headers, config){ deferred.reject(status); console.log(status); }); return deferred.promise; } } }
After we get the answer, whether the user entered the data correctly or not. If successful, returns: success: true, otherwise: success: false.
QUESTION: If the answer is false, how to leave the user on the same page? and in the case of c true, allow the transition to the next one (the link is bolted to the button). Please tell me how you can do this, or share links to relevant articles!
PS: I use ui-router routing.
$q.defer()
, and secondly - to use the button block element inside inline - the links are somehow not very, and it is not clear why. Click handler can be hung on the link - Grundysend
function - Grundy$q.defer()
- if the$http()
function already returns the promise to you? - Pavel Mayorov