Experiencing an issue with AngularJS $http.post. After completing the post requests, the form instead of returning the JSON response, it instead redirects to 127.0.0.1:8000/api/forms/create. The backend response is done with Django Rest Framework. This is a CORs request. The angularJS form is hosted on port 9000 making a call to port 8000. When the server is turned off, instead of returning the error alert, it insteads returns a page not found and the url is once again redirected to 127.0.0.1:8000/api/forms/create. Appreciate any advice.
Below is the controller code for Angular script:
'use strict';
angular.module('myApp')
.controller('DemoController', function ($scope, $http, DemoService, Tools) {
var form_submit = function() {$http.post("127.0.0.1:8000/api/forms/create", {name:$scope.applicant, date:$scope.date, address=$scope.address}).success(function(data){ alert(data); })
.error(function(error){
alert('something failed');
})};
});
Below is the index.html:
<!DOCTYPE html>
<head>
</head>
<body ng-app="myApp" ng-submit="form_submit()">
<FORM action="http://127.0.0.1:8000/api/forms/create/" method="post">
<INPUT type="text" ng-model="applicant" name="name">
<INPUT type="text" ng-model="date" name="date">
<INPUT type="text" ng-model="address" name="address">
<INPUT type="submit" value="Send">
</FORM>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js"></script>
<script src="controllers/demo.js"></script>
</html>