Created
January 22, 2010 19:44
-
-
Save bschwartz/284072 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
// This is a jQuery monkey-patch that changes all PUT and DELETE requests | |
// into POST requests and sets a "_method" param to the original request method. | |
// | |
// This is a workaround for the fact that some corporate networks and | |
// environments don't allow PUT and DELETE requests. | |
// | |
// This whole thing works because Rails implements the _method hack. | |
(function(){ | |
var ajaxWithoutMethodHack = jQuery.ajax; | |
jQuery.ajax = function( s ) { | |
if (s.type == "PUT" || s.type == "DELETE") { | |
if ( s.data && typeof s.data === "object" ) { | |
s.data._method = s.type; | |
} else if (s.data && typeof s.data === "string" ) { | |
s.data = s.data + '&_method=' + s.type; | |
} else { | |
s.data = {'_method': s.type}; | |
} | |
s.type = 'POST'; | |
} | |
ajaxWithoutMethodHack(s); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment