且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送带有angularjs $ http.delete()请求数据?

更新时间:2022-10-29 13:53:05

您不能做通过像/用户/ 1 /角色/ 2 URL的DELETE?我认为这是做的最RESTful方式。

否则,我想你可以通过用户ID作为查询参数的一部分?类似

  $ http.delete('/角色/+角色ID,{params:一个{用户名:用​​户ID}}),然后...

I have a resource 'roles' which has a many to many relationship with 'user'. To administer 'roles' I need to send the role id and the user id to the server so that it removes the the role from the correct user (not necessarily the logged in user)

Here is what I was attempting but according to the docs this is not possible. I know I can send the two ids in the uri but my laravel backend automatically sets up a resourceful route of resource/{resourceid} which I would like to use if possible. Is there a way to do this that I am missing?

var removeRole = function (roleid, userid) {
        var input =[];
        input.user = userid;

        $http.delete('/roles/' + roleid, input).success(function (data, status) {
            console.log(data);
        });
    };

You can't do a DELETE via a URL like /users/1/roles/2 ? I think that would be the most RESTful way to do it.

Otherwise I guess you can just pass the user id as part of the query params? Something like

$http.delete('/roles/' + roleid, {params: {userId: userID}}).then...