【发布时间】:2016-05-06 20:01:43
【问题描述】:
我正在尝试通过邮寄一个带有restangular的json,但这不会给我任何回报。
代码:
$scope.userPost = {
title: 'foo',
body: 'bar',
userId: 1
}
$scope.registerUser=function(){
$scope.people = Restangular.all('post').post($scope.userPost);
console.log($scope.people);
}
它返回给我这个:
{ "restangularCollection": false, "$object": {} }
http://jsonplaceholder.typicode.com/post 404 (Not Found)
通常我将它与 ajax 一起使用,它会返回一个 json:
$.ajax('http://jsonplaceholder.typicode.com/posts', {
method: 'POST',
data: {
title: 'foo',
body: 'bar',
userId: 1
}
}).then(function(data) {
console.log(data);
});
有什么想法吗?
【问题讨论】:
-
http://jsonplaceholder.typicode.com/post!==http://jsonplaceholder.typicode.com/posts也返回一个承诺,所以你需要使用Restangular.all('post').post($scope.userPost).then(function(data) { console.log(data); });得到响应
标签: angularjs json rest restangular