4

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

Dave Morris
  • 856
  • 9
  • 25
  • It seems awfully hard to find info on this. I'd say try out. If it works with the major browsers, it's fine; otherwise, you'll have to find a workaround. It's possible verbs unknown to the browser are blocked by some. – Pekka Jul 20 '10 at 19:12
  • Related: http://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers – Pekka Jul 20 '10 at 19:13
  • I tried in Chrome, and it sends a proper MERGE verb, but it doesn't include the request payload, which is kind of an essential part. I'm going to try out the method tunneling thing in the Alex's post below. Thanks for your help! – Dave Morris Jul 21 '10 at 03:43

3 Answers3

6

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

Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • 3
    Jacob's correct, it's not jQuery stopping you here but the browser's implementation of XmlHttpRequest. For example, IE doesn't support `PUT` either. – Nick Craver Jul 20 '10 at 19:12
4

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

Alex James
  • 20,874
  • 3
  • 50
  • 49
1

Found through this question, here is a blog article that looks interesting.

The answer - at least in 2008 - if I read it correctly:

  • IE seems not to support it (at least up to Version 7)

  • Firefox supports it

  • Opera turns everything unknown into a GET request

I think you'll have to try it out.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088