FND / jquery

jQuery plugins

This URL has Read+Write access

jquery / jquery.methodhack.js
100644 22 lines (19 sloc) 0.454 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function($) {
 
var _ajax = $.ajax;
$.ajax = function(options) {
if(options && $.inArray(options.type, ["PUT", "DELETE"]) != -1) {
var method = options.type;
var setup = options.beforeSend;
options.type = "POST";
options.beforeSend = function(xhr) {
xhr.setRequestHeader("X-HTTP-Method", method);
if(setup) {
return setup.apply(this, arguments);
} else {
return true;
}
};
}
_ajax.apply(this, arguments);
};
 
})(jQuery);