Skip to content

Instantly share code, notes, and snippets.

@stevobengtson
Created April 14, 2015 00:18
Show Gist options
  • Save stevobengtson/35dbb6b5b54bc8db803b to your computer and use it in GitHub Desktop.
Save stevobengtson/35dbb6b5b54bc8db803b to your computer and use it in GitHub Desktop.
jQuery ajax shorthands
jQuery.each( [ "put", "patch", "delete" ], 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