Skip to content

Instantly share code, notes, and snippets.

@emptyhammond
Created January 12, 2012 21:11
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save emptyhammond/1603144 to your computer and use it in GitHub Desktop.
Save emptyhammond/1603144 to your computer and use it in GitHub Desktop.
Make a PUT request with jQuery.ajax()
$.ajax({
type: 'POST', // Use POST with X-HTTP-Method-Override or a straight PUT if appropriate.
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 PUT.
data: '{"name": "Dave"}' // Some data e.g. Valid JSON as a string
});
/* Some clients do not support PUT or it’s difficult to send in a PUT request. For these cases, you could POST the request with a request header of X-HTTP-Method-Override set to PUT. What this tells the server is that the intended request is a PUT. Obviously this relies on the API you are accessing making use of the X-HTTP-Method-Override Header.*/
@t0rton
Copy link

t0rton commented Oct 20, 2015

Can I send FormData() to the php API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment