I’ve found quite a few posts that say the following should work:
$.ajax
({
type: "PUT",
url: "http://localhost:3000/api/v1/markets/4/features/9?token=qqMJpyFbnqXVyPRLCwrv",
dataType: 'script',
data: "title=from form&content=this is content from the form",
success: function () {
alert("Thanks!");
}
})
Unfortunately, the server log states Started GET “/api/v1/…” and returns a status of 200.
The following does work.
curl -X PUT -d 'feature[content]=this is the content' -d 'feature[title]=new title' http://localhost:3000/api/v1/markets/4/features/9?token=qqMJpyFbnqXVyPRLCwrv
So I know that my update action in the api controller is functioning correctly. I have articles that we hope to syndicate, and would like the consumers of that data to be able to comment on them without leaving their current location.
Any help or links that I may not have already googled is appreciated.
Unfortunately you can’t send PUT request with XHR from browser environment only GET and POST methods are valid across browsers.
With little modification your script will work:
key here is _method: ‘PUT’ in data object, this way you can override actual HTTP method(in this case POST).
P.S.
I changed “data: ” property slightly and assigned object instead of string. This way jQuery will take care on string encoding.