$resource send data in get insted of post

I am try to post data form $resource in angular js project. It is my code in factory

deletemenu: function(menudata ) {
            return $resource(url+'/menu/delete', {}, {
                   delete_menu: { 
                            method: 'POST',
                            params: {
                               entityType    : menudata.entityType  ,
                               sellerId      : menudata.sellerId  ,
                               menuId        : menudata.menuId  ,
                               parentMenuIds : menudata.parentMenuIds , 
                               menuItemId    : menudata.menuItemId   
                            }, 
                            isArray: false
                          }
            }).deletemenu();
        }

I declare method POST but the request is send as a query string not the post request. It send as a

URL+"menu/delete?entityType=I&menuId=25&menuItemId=20&parentMenuIds=4&sellerId=1"

How I send these data as a POST method.


I think this should work better for you

return $resource(url + '/menu/delete', null, {
    delete_menu: {method: 'POST'}
}).delete_menu(menudata);

Here, I'm passing in the menudata as the first argument to the non-GET "class" action delete_menu which will use it as postData .


The objects returned by $resource are much more flexible than what you're using here. It looks like you should be able to make your service / factory much neater by returning the $resource instance instead of these individual functions. For example

.factory('menuFactory', function($resource) {
    var url = 'whatever';

    return $resource(url, null, {
        delete: {
            url: url + '/menu/delete',
            method: 'POST'
        } //, other actions here
    });
})

Then you can call it with

menuFactory.delete(menuData)
链接地址: http://www.djcxy.com/p/77654.html

上一篇: 如何在1.5版本中以$ angularjs取消承诺

下一篇: $资源发送数据在后期获取