Skip to content

Instantly share code, notes, and snippets.

@ronnyhaase
Last active August 29, 2015 14:15
Show Gist options
  • Save ronnyhaase/d69ff459fef5d6d94440 to your computer and use it in GitHub Desktop.
Save ronnyhaase/d69ff459fef5d6d94440 to your computer and use it in GitHub Desktop.
Extend jQuery AJAX shorthand methods by missing HTTP verbs
jQuery.each(['put', 'delete', 'options'], function(i, method) {
jQuery[method] = function(url, data, callback, type) {
// Shift arguments if data argument was omitted
if ( jQuery.isFunction(data) ) {
type = type || callback;
callback = data;
data = undefined;
}
// The url can be an options object (which then must have .url)
return jQuery.ajax(jQuery.extend({
url: url,
type: method,
dataType: type,
data: data,
success: callback
}, jQuery.isPlainObject(url) && url));
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment