jQuery 如何在ajax DELETE请求中传递数据而不是headers
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15088955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass data in the ajax DELETE request other than headers
提问by Prats
Below is my Ajax request for a DELETE
request:
以下是我的 AjaxDELETE
请求:
deleteRequest: function (url, Id, bolDeleteReq, callback, errorCallback) {
$.ajax({
url: urlCall,
type: 'DELETE',
headers: {"Id": Id, "bolDeleteReq" : bolDeleteReq},
success: callback || $.noop,
error: errorCallback || $.noop
});
}
Is there any alternative way to pass the data other than in the headers
?
除了在headers
.
回答by Gabriele Petrioli
Read this Bug Issue: http://bugs.jquery.com/ticket/11586
阅读此错误问题:http: //bugs.jquery.com/ticket/11586
Quoting the RFC 2616 Fielding
The
DELETE
method requests that the origin server delete the resource identified by the Request-URI.
该
DELETE
方法请求源服务器删除由 Request-URI 标识的资源。
So you need to pass the data in the URI
所以需要在URI中传递数据
$.ajax({
url: urlCall + '?' + $.param({"Id": Id, "bolDeleteReq" : bolDeleteReq}),
type: 'DELETE',
success: callback || $.noop,
error: errorCallback || $.noop
});
回答by dinith jayabodhi
I was able to successfully pass through the data attribute in the ajax method. Here is my code
我能够成功地通过ajax 方法中的数据属性。这是我的代码
$.ajax({
url: "/api/Gigs/Cancel",
type: "DELETE",
data: {
"GigId": link.attr('data-gig-id')
}
})
The link.attrmethod simply returned the value of 'data-gig-id'.
该link.attr方法简单地返回的值 “数据演出ID”。
回答by K D
deleteRequest: function (url, Id, bolDeleteReq, callback, errorCallback) {
$.ajax({
url: urlCall,
type: 'DELETE',
data: {"Id": Id, "bolDeleteReq" : bolDeleteReq},
success: callback || $.noop,
error: errorCallback || $.noop
});
}
Note: the use of headers
was introduced in JQuery 1.5.:
注意:headers
在 JQuery 1.5. 中引入了使用:
A map of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.
与请求一起发送的附加标头键/值对的映射。此设置在调用 beforeSend 函数之前设置;因此,headers 设置中的任何值都可以从 beforeSend 函数中被覆盖。