Created
March 11, 2015 22:27
-
-
Save 2bj/c77787e4716e3003bfb2 to your computer and use it in GitHub Desktop.
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( [ ["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 | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now we have$.update() and $ .delete() shorthand methods.