Skip to content

Instantly share code, notes, and snippets.

@2bj
Created March 11, 2015 22:27
Show Gist options
  • Save 2bj/c77787e4716e3003bfb2 to your computer and use it in GitHub Desktop.
Save 2bj/c77787e4716e3003bfb2 to your computer and use it in GitHub Desktop.
jQuery.each( [ ["update", "PATCH"], ["delete", "DELETE"] ], function( i, method ) {
jQuery[method[0]] = function (url, data, callback, type) {
if (jQuery.isFunction(data)) {
type = type || callback;
callback = data;
data = undefined;
} else {
if (data === undefined) {
data = {_method: method[1]};
} else {
data['_method'] = method[1];
}
}
return jQuery.ajax({
url: url,
type: 'post',
dataType: type,
data: data,
success: callback
});
};
});
@2bj
Copy link
Author

2bj commented Mar 11, 2015

Now we have $.update() and $.delete() shorthand methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment