Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom HTTP Verb with jQuery.ajax()

Tags:

jquery

ajax

odata

Is it possible to use a custom HTTP VERB, like MERGE, with jQuery.ajax()? I'm interacting with an OData API, which expects a MERGE verb when posting updates to records.

The problem I'm having is that when I use "MERGE" in the ajax() request, it doesn't send data to the server. It just sends a MERGE request with no data, so the OData service rejects it.

When I change the request to a PUT, the OData service sends back a 500 error.

My options are basically to figure out how to get "MERGE" calls to send the data along with the request, do a DELETE followed by a POST (delete and recreate the record on every update), or figure out how to modify the OData service to accept PUTs for updates.

Let me know if you have any ideas on how to make jQuery.ajax() send the data with a MERGE request.

Thanks,

Dave

like image 842
Dave Morris Avatar asked Dec 22 '22 01:12

Dave Morris


2 Answers

This is not a question of jQuery's ability to handle custom HTTP verbs, this depends on the browser.

like image 175
Jacob Relkin Avatar answered Jan 07 '23 04:01

Jacob Relkin


OData supports tunneling MERGE through POST - which of course is supported via JQuery - by adding the X-HTTP-Method header.

See this thread for more

Alex

OData Program Manager Microsoft

like image 32
Alex James Avatar answered Jan 07 '23 04:01

Alex James