Could anyone tell me why the following statement does not send the post data to the designated url? The url is called but on the server when I print $_POST - I get an empty
I use jQuery param with AngularJS post requrest. Here is a example ... create AngularJS application module, where myapp
is defined with ng-app
in your HTML code.
var app = angular.module('myapp', []);
Now let us create a Login controller and POST email and password.
app.controller('LoginController', ['$scope', '$http', function ($scope, $http) {
// default post header
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
// send login data
$http({
method: 'POST',
url: 'https://example.com/user/login',
data: $.param({
email: $scope.email,
password: $scope.password
}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
// handle success things
}).error(function (data, status, headers, config) {
// handle error things
});
}]);
I don't like to exaplain the code, it is simple enough to understand :) Note that param
is from jQuery, so you must install both jQuery and AngularJS to make it working. Here is a screenshot.
Hope this is helpful. Thanks!