Last active
August 29, 2015 14:15
-
-
Save ronnyhaase/d69ff459fef5d6d94440 to your computer and use it in GitHub Desktop.
Extend jQuery AJAX shorthand methods by missing HTTP verbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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