Is there a way to see if a client browser supports PUT or SEARCH methods for usage with JQuery & AJAX requests?
- HTML5 PUT/DELETE methods not working in Chrome?
- Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
I have the following code, and PUT does not appear on the server side for me in Chromium and Chrome … I’d like to know, if PUT isn’t supported by the browser, how to change it to a POST request … for backwards compatibility
function do_data(url, action, query) {
try {
if ($.browser.msie) {
var xdr = new XDomainRequest();
if (query !== null) {
console.log(query);
xdr.open(action, url + '?' + $.param(query));
} else {
xdr.open(action, url);
}
xdr.onload = function() {
var data = $.parseJSON(this.responseText);
show_data(data);
};
xdr.send();
} else {
if (query !== null) {
$.ajax({
url: url,
data: query,
type: action,
success: function(data) {
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
}
});
} else {
console.log(query);
$.ajax({
url: url,
type: action,
success: function(msg) {
console.log(data);
}
});
}
}
} catch (e) {}
}
Using the above code, if I use “PUT” on Chromium / Chrome, error: function(jqXHR, textStatus, errorThrown) will print out simply error.
On the server side, I see the REQUEST_METHOD: OPTIONS and not PUT.
Just to confirm, for anyone who comes across this … there isn’t a programmatic way
The common way of handling the lack of PUT and DELETE support in most browsers is to use HTTP POST tunneling. Basically you use a POST and add the real VERB to a X-HTTP-Method-Override HTTP header. On the service you check for the latter, if not found use the normal HTTP method.
See here for more info.