AngularJS не создает JSON по желанию. С кодом (ниже) он генерирует массив (сериализованный пар), но не формируется. т.е. я получаюJSON POST с помощью AngularJS
{
data : 'value',
date : 'value'
}
Но хотел - JSON т.е.
{
"data" : "value",
"date" : "value"
}
Код для угловатых POST JSON является (сниппет)
<script>
// Defining angularjs application.
var postApp = angular.module('postApp', []);
// Controller function and passing $http service and $scope var.
postApp.controller('postController', function($scope, $http) {
// create a blank object to handle form data.
$scope.user = {};
// calling our submit function.
$scope.submitForm = function() {
// Posting data to php file
$http({
method : 'POST',
url : 'user.php',
data :JSON.stringify($scope.user),
headers : {'Content-Type': 'application/json'}
})
.success(function(data) {
if (data.errors) {
// Showing some error which has to come from server
} else {
$scope.message = data.message; //make the json
}
});
};
});
</script>
Что я должен сделать, чтобы получить JSON и не массив?
не могли бы вы рассказать нам, что такое $ scope.user –