编程的方法,如果客户端浏览器支持PUT / DELETE方法方法、客户端、浏览器、DELETE

2023-09-10 13:40:32 作者:旧城失词‖soul ≈

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

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

HTML5 PUT / DELETE方法不工作中铬? 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.

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