Ajax Chrome在重定向时取消CORS XHR

Ajax Chrome在重定向时取消CORS XHR,ajax,google-chrome,redirect,cors,http-response-codes,Ajax,Google Chrome,Redirect,Cors,Http Response Codes,我遇到了一个神秘的问题,Chrome会在遇到HTTP重定向时取消跨源AJAX请求。在“网络”选项卡中,它显示为“(已取消)”,响应标题或正文不可用 以下是流程: 在http上加载页面:// 在https上发布登录端点的请求:// 303答复 请求已取消 以下是JS(来自ajaxtest.html): Chrome的网络内部显示服务器响应了以下标题: HTTP/1.1 303 See Other Date: Thu, 05 Sep 2013 17:54:21 GMT Server: Apache/

我遇到了一个神秘的问题,Chrome会在遇到HTTP重定向时取消跨源AJAX请求。在“网络”选项卡中,它显示为“(已取消)”,响应标题或正文不可用

以下是流程:

  • 在http上加载页面://
  • 在https上发布登录端点的请求://
  • 303答复
  • 请求已取消
  • 以下是JS(来自
    ajaxtest.html
    ):

    Chrome的网络内部显示服务器响应了以下标题:

    HTTP/1.1 303 See Other
    Date: Thu, 05 Sep 2013 17:54:21 GMT
    Server: Apache/2
    Access-Control-Allow-Origin: http://dev.example.com
    Access-Control-Allow-Credentials: true
    Location: https://dev.example.com/appName-rest/j_spring_cas_security_check?ticket=xxxx.example.com
    Vary: Accept-Encoding,User-Agent
    Content-Encoding: gzip
    Content-Length: 52
    Connection: close
    Content-Type: text/plain; charset=UTF-8
    
    上面写着:URL\u请求\u阻止\u委托


    有人知道这失败的原因吗?

    此方法发送了两次:r.send()

    请尝试以下方法

        var xhr = new XMLHttpRequest();
        xhr.open("POST", "YOUR_URL", true);
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    
        xhr.onreadystatechange = function (event) {
            if (xhr.readyState === 4 && xhr.status === 200) { // if complete and success
                return xhr.responseText;
            }
        };
        xhr.withCredentials = true; // OPTIONAL : I don't know if you need it for CORS Requests
        xhr.send("username=YOUR_USERNAME&password=YOUR_PASSWORD");
    

    似乎您正在尝试这样做,因为您设置了“内容类型”:“应用程序/json”。带有重定向的预飞请求被拒绝。

    您使用的是WebService吗?不确定。。我认为是这样。但代码只是简单的javascript。
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "YOUR_URL", true);
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    
        xhr.onreadystatechange = function (event) {
            if (xhr.readyState === 4 && xhr.status === 200) { // if complete and success
                return xhr.responseText;
            }
        };
        xhr.withCredentials = true; // OPTIONAL : I don't know if you need it for CORS Requests
        xhr.send("username=YOUR_USERNAME&password=YOUR_PASSWORD");