本文介绍了发送带有angularjs $ http.delete()请求数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个资源角色具有许多与用户一对多关系。要管理角色我需要发送的角色ID和用户ID到服务器,以便它会从正确的用户角色(不一定登录的用户)

下面是我试图而是根据这是不可能的。我知道我可以送两个ID中的URI,但我laravel后台自动设置资源/ {} RESOURCEID一个足智多谋的路线,我想如果可能的话使用。有没有办法做到这一点,我很想念?

  VAR removeRole =功能(角色ID,用户ID){
        无功输入= [];
        input.user =用户标识;        $ http.delete('/角色/+角色ID,输入).success(功能(数据,状态){
            的console.log(数据);
        });
    };


解决方案

您不能做通过像/用户/ 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...

这篇关于发送带有angularjs $ http.delete()请求数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:14