Restangular POST always empty

◇◆丶佛笑我妖孽 提交于 2019-12-01 16:07:26

问题


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);

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

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?


回答1:


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");
})

Check the post method here: https://github.com/mgonto/restangular#element-methods

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

Bests!



来源:https://stackoverflow.com/questions/17302395/restangular-post-always-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!