How to pass data in the ajax DELETE request other than headers
JqueryAjaxJquery Problem Overview
Below is my Ajax request for a DELETE
request:
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
?
Jquery Solutions
Solution 1 - Jquery
Read this Bug Issue: 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.
So you need to pass the data in the URI
$.ajax({
url: urlCall + '?' + $.param({"Id": Id, "bolDeleteReq" : bolDeleteReq}),
type: 'DELETE',
success: callback || $.noop,
error: errorCallback || $.noop
});
Solution 2 - Jquery
I was able to successfully pass through the data attribute in the ajax method. Here is my code
$.ajax({
url: "/api/Gigs/Cancel",
type: "DELETE",
data: {
"GigId": link.attr('data-gig-id')
}
})
The link.attr method simply returned the value of 'data-gig-id' .
Solution 3 - Jquery
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.:
> 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.