Restangular POST总是空 [英] Restangular POST always empty

查看:155
本文介绍了Restangular POST总是空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我不理解一个POST是如何在一个RESTful API来完成。当创建在Restangular一个新的对象,这样的:

I think I'm not understanding how a POST is done in a RESTful api. When creating a new object in Restangular with this:

var user = {name: "John", id:"123"};
Restangular.one('building','5').post(user);

我希望它通过与用户的URL example.com/api/building/5值的$ _POST阵列

I expect it to pass a $_POST array with the values of user to the url example.com/api/building/5

和右知道这是做一个POST请求到正确的脚本,但在$ _POST数组为空。任何想法,我做错了什么?

And right know it's doing a POST request to the correct script but the $_POST array is empty. Any idea of what I'm doing wrong?

推荐答案

我Restangular的创造者。帖子应做的集合,而不是元素。所以,如果你想将用户添加到楼,你应该做的是这样的:

I'm the creator of Restangular. Posts should be done to collections, not to elements. So, if you want to add a user to the building, you should do something like:

Restangular.one("building", 5).post('users', user).then(function(postedUser) {
    console.log("Success");
})

在这里查看POST方法:<一href=\"https://github.com/mgonto/restangular#element-methods\">https://github.com/mgonto/restangular#element-methods

签名是路径指明子元素集合,元素POST。

The signature is path to subelement collection, element to POST.

最好成绩!

这篇关于Restangular POST总是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆