I am facing some challenges when trying to send an http post request to the server. I am using PhoneGap to develop an application that utilizes AngularJS. Can someone guide me on how to make a post request using AngularJS? Here is a snippet of my code:
.controller('loginCtrl', function($scope, $http , $state, $ionicPopup, AuthService) {
$scope.login = function(data) {
AuthService.login(data.username, data.password).then(function TestController($scope) {
$scope.username = $http({
url: 'http://samedomain.com/GetPersons',
method: "POST",
data: email="email",
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
$scope.data = data; // how do pass this to $scope.persons?
}).error(function (data, status, headers, config) {
alert(error);
$scope.status = status;
});
});
};
However, upon running this code, I encountered an error message:
Error: Unexpected request: POST http://192.168.30.196:8086/user/login
No more request expected
at $httpBackend (http://192.168.30.60:3000/lib/angular-mocks/angular-mocks.js:1418:9)
at sendReq (http://192.168.30.60:3000/lib/ionic/js/ionic.bundle.js:24793:9)
at serverRequest (http://192.168.30.60:3000/lib/ionic/js/ionic.bundle.js:24503:16)
... (additional error details here)...