Created
January 31, 2011 12:12
-
-
Save a2ikm/803951 to your computer and use it in GitHub Desktop.
Extend jQuery with functions for PUT and DELETE requests.
This file contains hidden or 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
/* | |
* Extend jQuery with functions for PUT and DELETE requests. | |
* references: | |
* http://homework.nwsnet.de/news/9132_put-and-delete-with-jquery | |
* http://stackoverflow.com/questions/4007605/using-http-put-to-send-json-with-jquery-and-rails-3 | |
*/ | |
(function($) { | |
function _ajax_request(url, data, callback, type, method) { | |
if ($.isFunction(data)) { | |
callback = data; | |
data = {}; | |
} | |
return $.ajax({ | |
type: method, | |
url: url, | |
data: data, | |
success: callback, | |
dataType: type, | |
beforeSend: function(xhr){ | |
xhr.setRequestHeader("X-Http-Method-Override", method.toLowerCase()); | |
} | |
}); | |
} | |
$.extend({ | |
"put": function(url, data, callback, type) { | |
return _ajax_request(url, data, callback, type, 'PUT'); | |
}, | |
"delete": function(url, data, callback, type) { | |
return _ajax_request(url, data, callback, type, 'DELETE'); | |
} | |
}) | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment