2

According to jQuery's documentation $.ajax() supports "other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not [necessarily] supported by all browsers." [1]

I'm wondering if there is a way to check if a browser supports a given method, e.g. PATCH, PUT, DELETE, etc. and gracefully degrade to a POST method using $.ajaxPrefilter() if it is unsupported? Or, is it better to just always POST from the form or AJAX call and use some other context (e.g. _method, or server supported X-header) to indicate the intended method, rather than what was actually used?

UPDATE: It appears that one way to test whether a particular request type is supported is to actually make the request, e.g.

var x=new XMLHttpRequest();
x.open("patch", "/");
x.send(null);

However, I'd like to avoid making any requests when determining support for particular request types, if possible.

Sean Quinn
  • 2,131
  • 1
  • 18
  • 48
  • http://stackoverflow.com/questions/1757187/which-browsers-dont-support-a-http-delete-with-jquery-ajax – dandavis Nov 08 '13 at 22:32
  • Thanks, I already read that question (and the linked one it was marked a duplicate of) but neither really answers the question as to how to check for a particular browser's support, in JavaScript, of an arbitrary request method. For instance, all new browsers should accept `PATCH` but older browsers may not. For those browsers it would be important to know this and perform the appropriate action(s). Hence the question: how can support for a particular request method be detected? – Sean Quinn Nov 08 '13 at 22:37
  • you can use try/catch to degrade in almost any situation of unknown host controls. i was using PROPGET on IE7 if that helps, i doubt you should go further back in time than that... – dandavis Nov 08 '13 at 22:39
  • @dandavis fair enough, beyond attempting to open an XHR request using a particular method (e.g. `PATCH`) as mentioned above in my edit and falling through a few `try/catch` statements, which I'm not really keen on doing, I was hoping there might be a way of detecting capabilities--something like: `XMLHttpRequest.isMethodSupport('PATCH')` (Saw your edit, I'll look at PROPGET as well, thanks!) – Sean Quinn Nov 08 '13 at 22:42
  • 2
    something not modern enough to use said methods is not likely to implement a proprietary capability refection API. i don't want to dismiss the question, it's a good one, but if there were an easy go-to answer you'd have found it by now... I think uppercase METHOD anything works in IE7 and nobody really much uses old minor browsers... – dandavis Nov 08 '13 at 22:44
  • @dandavis very true. Any way, it looks like I have a little more to go on, right now I'm leaning towards just using the `_method` or supported X-header approach and transforming anything non-standard. At least it would give a consistency to the code. Thanks! :) – Sean Quinn Nov 08 '13 at 22:47

0 Answers0