app.controller("blankCtrl", ['$scope', '$http', '$parse', function($scope, $http, $parse) {
$scope.login = function() {
$scope.spice = 'tooo';
console.log("hiii");
alert($("#loginform").serialize()); //-------mobile=9860292514&password=123456
// $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
// $httpProvider.defaults.headers.post['Content-Type'] = 'application/JSON';
var dataObj = {
mobile: $scope.mobile,
password: $scope.password
};
$http({
method: 'POST',
url: 'http://edudux.com/manage/index.php?/api/login',
data:dataObj,
headers: {
'Content-Type': 'application/json'
}
})
.success(function(data, status, headers, config) {
alert("status" + status); //-----------status200
alert(angular.isObject(JSON)); // --------true
alert(JSON); //-------------[object JSON]
var a = angular.toJson(dataObj);
alert(a); //----------{}
var b = angular.fromJson(dataObj);
alert(b); //------------[object Object]
alert(data); //----------[object Object]
alert(JSON.stringify(dataObj)); //----------{}
console.log(JSON.stringify(dataObj));
})
.error(function(data, status, headers, config) {
alert(status);
});
};
}]);
I am new to AngularJS, and developing a new application using AngularJS. I try to post a JSON Object with AngularJS $http Server. But I get an empty object as a response : "{}"