我有一个看起来像这样的订单资源.
.factory('Order',order) order.$inject = ['$resource',"ApiEndpoint"]; function order($resource,ApiEndpoint) { return $resource(ApiEndpoint.url + 'orders.json',{},{ create: {method: 'POST',url: ApiEndpoint.url + 'orders.json'},update: {method: 'PUT'},edit: {method: 'GET',url: ApiEndpoint.url + 'orders/edit.json'},remove_item: {method: 'GET',url: ApiEndpoint.url + 'orders/remove_item.json'},}); }
当我像这样运行Order.update时
var params = { order: { line_items_attributes: {0: {quantity: 2,id: 1}} },order_id: 3 }; Order.update(params,function (resp,respHeaders) { console.log("response headers",respHeaders()); console.log("change quantity resp",resp); })
我也试过这个:
Order.update({},params,resp); })
发送到服务器的params最终位于URL内.例如,这是服务器收到的网址之一
path="/api/mobile/orders.json?order=%7B%22line_items_attributes%22:%7B%220%22:%7B%22quantity%22:8,%22id%22:356265%7D%7D%7D"
我还应该注意,服务器接收的方法是OPTIONS请求.服务器已设置为处理此问题.
由于我发送了一个PUT请求,为什么$resource通过URL传递params而不是有效负载的一部分?