【问题标题】:ConnectFailure in AjaxPro on certain browsers某些浏览器上 AjaxPro 中的 ConnectFailure
【发布时间】:2014-09-22 19:31:02
【问题描述】:

此问题已在 PlayStation 3、4、Xbox360、Xbox One 上重现。所有版本的 AjaxPro 都存在此问题。

当发出 Ajax 请求(使用 AjaxPro)时,服务器会返回正确的内容。但是,回调函数中返回的对象是

{
   "error": 
    {
     "Message":"","Type":"ConnectFailure","Status":200},"value":null,
     "request":
     {
       "method":"MethodName",
       "args":
       {
          "Argument1":"1111","Argument2":"2222"
       }
     },
    "context":null,"duration":18
   }
}

【问题讨论】:

    标签: asp.net .net cross-platform ajaxpro


    【解决方案1】:

    在我的情况下,我在将 AjaxPro 与 https、TLS 1.2、ECDHE_RSA 与 P-256 密钥交换和 AES_256_GCM 密码(IE11+、Chrome51+、Firefox49+)一起使用时遇到了同样的错误。检查你的 here)。使用带有 HMAC-SHA1 密码的过时 AES_256_CBC 运行正常。

    问题是 XMLHttpRequest.statusText 属性在服务器响应(我真的不知道为什么)和 AjaxPro.Request.prototype.doStateChange 方法(ajaxpro/ core.ashx 文件)预期“OK”将响应视为有效:

    var res = this.getEmptyRes();
    if(this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK") {
        res = this.createResponse(res);
    } else {
        res = this.createResponse(res, true);
        res.error = {Message:this.xmlHttp.statusText,Type:"ConnectFailure",Status:this.xmlHttp.status};
    }
    

    我最终决定重写 AjaxPro.Request.prototype.doStateChange 方法并允许在 this.xmlHttp.statusText 中使用空值。

    我将此脚本添加到受影响的页面:

    $(function() {
        if (typeof AjaxPro != 'undefined' && AjaxPro && AjaxPro.Request && AjaxPro.Request.prototype) {
            AjaxPro.Request.prototype.doStateChange = function () {
                this.onStateChanged(this.xmlHttp.readyState, this);
                if (this.xmlHttp.readyState != 4 || !this.isRunning) {
                    return;
                }
                this.duration = new Date().getTime() - this.__start;
                if (this.timeoutTimer != null) {
                    clearTimeout(this.timeoutTimer);
                }
                var res = this.getEmptyRes();
                if (this.xmlHttp.status == 200 && (this.xmlHttp.statusText == "OK" || !this.xmlHttp.statusText)) {
                    res = this.createResponse(res);
                } else {
                    res = this.createResponse(res, true);
                    res.error = { Message: this.xmlHttp.statusText, Type: "ConnectFailure", Status: this.xmlHttp.status };
                }
                this.endRequest(res);
            };
        }
    });
    

    【讨论】:

      【解决方案2】:

      在此之前的所有答案的基础上,供其他人参考 - 在我们的情况下,我们将其追踪到 HTTP2 协议(注意 - 我们正在通过 HTTPS 进行测试;我不确定是否存在HTTP 问题...)。
      - 当我们在浏览器(或服务器上的 IIS)中禁用 HTTP2 时,AjaxPro 调用正常工作。
      - 但是,当使用 HTTP2 时,响应是简单的“200”而不是“200 OK”,AjaxPro 将其解释为失败

      【讨论】:

      • 在 IIS 10 中,当您在站点绑定中选择 HTTPS 时,您可以禁用 HTTP/2
      【解决方案3】:

      这个问题的提示在

      "Message":""
      

      AjaxPro 的 core.ashx 文件是使用 core.js 生成的

      在core.js中,以下代码负责在收到服务器的响应时生成响应对象。

         if (this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK") {
              res = this.createResponse(res);
          } else {
              res = this.createResponse(res, true);
              res.error = { Message: this.xmlHttp.statusText, Type: "ConnectFailure", Status: this.xmlHttp.status };
          }
      

      由于某种原因,已识别平台上的浏览器不会将 xmlHttp.statusText 返回为“OK”。相反,它是空的。这会导致 AjaxPro 陷入“ConnectionFailure”子句。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-29
        • 1970-01-01
        • 1970-01-01
        • 2015-10-04
        • 2016-04-23
        • 1970-01-01
        • 2016-10-28
        • 1970-01-01
        相关资源
        最近更新 更多