Last active
November 29, 2019 01:52
-
-
Save dataserver/a697ab647be61221eccff76e9defdf62 to your computer and use it in GitHub Desktop.
Use ajax POST method with X-HTTP-Method-Override to workaround when you can't use PUT/DELETE/XXX
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
$.ajax({ | |
type: 'POST', // Use POST with X-HTTP-Method-Override | |
dataType: 'json', // Set datatype - affects Accept header | |
url: "http://example.com/people/1", // A valid URL | |
headers: {"X-HTTP-Method-Override": "PUT"}, // X-HTTP-Method-Override set to XXX. | |
data: {"name": "John Doe"} | |
}); | |
/* | |
Some clients do not support PUT or other method beyond GET/POST. | |
When I was trying to implement a REST server on phpDesktop, | |
the Mongoose server had problems accepting PUT, DELETE, PATCH | |
methods. | |
For these cases, you could use POST with a request header of | |
X-HTTP-Method-Override set to PUT/DELETE/PATCH. | |
What this tells the server is that the intended request is a XXX. | |
PHP, check for $_SERVER['X_HTTP_METHOD_OVERRIDE'] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment