编程的方法,如果客户端浏览器支持PUT / DELETE方法 [英] Programmatic way to see if client browser supports PUT / DELETE methods

查看:229
本文介绍了编程的方法,如果客户端浏览器支持PUT / DELETE方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法,看是否有客户端浏览器支持PUT或搜索方法的用法jQuery和放大器; AJAX请求?

Is there a way to see if a client browser supports PUT or SEARCH methods for usage with JQuery & AJAX requests?

  • <一个href="http://stackoverflow.com/questions/3378894/html5-put-delete-methods-not-working-in-chrome">HTML5 PUT / DELETE方法不工作中铬?
  • <一个href="http://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers">Are在大多数Web浏览器中可用的PUT,DELETE,HEAD等方法?
  • HTML5 PUT/DELETE methods not working in Chrome?
  • Are the PUT, DELETE, HEAD, etc methods available in most web browsers?

我有以下的code和 PUT 没有出现在铬和铬,我在服务器端...我想知道,如果说就是不支持浏览器,如何将它更改为POST请求......向后兼容性

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) {}
}

使用上述code,如果我使用PUT铬/铬,错误:函数(jqXHR,textStatus,errorThrown)将简单地打印出错误

在服务器端,我看到了REQUEST_METHOD:选项并没有投入。

On the server side, I see the REQUEST_METHOD: OPTIONS and not PUT.

只是为了确认,任何人谁遇到这...有没有一种编程方法

推荐答案

处理缺乏PUT和DELETE支持大多数浏览器的常用方法是使用HTTP POST隧道。基本上你使用POST和真正的动词添加到 X-HTTP-方法,覆盖 HTTP标头。在服务您检查后,如果未发现使用正常的HTTP方法。

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.

请参阅这里获取更多信息。

这篇关于编程的方法,如果客户端浏览器支持PUT / DELETE方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆