Skip to content

Instantly share code, notes, and snippets.

@splatch
Created April 14, 2011 16:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splatch/919831 to your computer and use it in GitHub Desktop.
Save splatch/919831 to your computer and use it in GitHub Desktop.
Extra http methods for jQuery based on X-HTTP-Method-Override header.
function _ajax_request(url, data, callback, type, method) {
if (jQuery.isFunction(data)) {
callback = data;
data = {};
}
return jQuery.ajax({
type: "POST",
url: url,
data: data,
success: callback,
dataType: type,
headers: {
"X-HTTP-Method-Override": method
}
});
}
jQuery.extend({
put: function(url, data, callback, type) {
return _ajax_request(url, data, callback, type, 'PUT');
},
delete_: function(url, data, callback, type) {
return _ajax_request(url, data, callback, type, 'DELETE');
}
});
$(document).ready(function() {
$.delete_("url", {}, function(data) {
alert(data)
}).error(defaultErrorHandler)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment