Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to send a PUT/DELETE request in jQuery?

GET:$.get(..)

POST:$.post()..

What about PUT/DELETE?
by

3 Answers

espadacoder11
You could use the ajax method:

$.ajax({
url: '/script.cgi',
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
pankajshivnani123
Here's an updated ajax call for when you are using JSON with jQuery > 1.9:

$.ajax({
url: '/v1/object/3.json',
method: 'DELETE',
contentType: 'application/json',
success: function(result) {
// handle success
},
error: function(request,msg,error) {
// handle failure
}
});
sandhya6gczb
We can extend jQuery to make shortcuts for PUT and DELETE:

jQuery.each( [ "put", "delete" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}

return jQuery.ajax({
url: url,
type: method,
dataType: type,
data: data,
success: callback
});
};
});

Login / Signup to Answer the Question.