angularjs – PUT请求通过URL发送params
发布时间:2020-12-17 18:08:40 所属栏目:安全 来源:网络整理
导读:我有一个看起来像这样的订单资源. .factory('Order',order)order.$inject = ['$resource',"ApiEndpoint"];function order($resource,ApiEndpoint) { return $resource(ApiEndpoint.url + 'orders.json',{},{ create: {method: 'POST',url: ApiEndpoint.url +
我有一个看起来像这样的订单资源.
.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而不是有效负载的一部分? 解决方法
从
docs:
有效负载是第二个参数,因此请尝试使用此代码 var params = { order: { line_items_attributes: {0: {quantity: 2,order_id: 3 }; Order.update({},resp); }) 只需将一个空对象作为第一个参数添加到update方法中. 还看看他与custom put requests相关的部分 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |