首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >某些浏览器上的ConnectFailure在AjaxPro中的应用

某些浏览器上的ConnectFailure在AjaxPro中的应用
EN

Stack Overflow用户
提问于 2014-09-22 19:31:02
回答 3查看 1.6K关注 0票数 5

此问题已在PlayStation 3,4,Xbox360,Xbox 1上转载。所有版本的AjaxPro都存在此问题。

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

代码语言:javascript
复制
{
   "error": 
    {
     "Message":"","Type":"ConnectFailure","Status":200},"value":null,
     "request":
     {
       "method":"MethodName",
       "args":
       {
          "Argument1":"1111","Argument2":"2222"
       }
     },
    "context":null,"duration":18
   }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-25 15:06:24

在我的例子中,当使用AjaxPro和https、TLS 1.2、ECDHE_RSA和P-256密钥交换以及AES_256_GCM密码(IE11+、Chrome51+、Firefox49+ )时,我也会遇到同样的错误。检查你的这里)。它运行好与过时的AES_256_CBC与HMAC-SHA1密码。

问题是,在服务器响应(我不知道原因)之后,XMLHttpRequest.statusText属性是空的,而AjaxPro.Request.prototype.doStateChange方法(ajaxpro/core.ashx文件)期望"OK“将响应作为有效的:

代码语言:javascript
复制
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中的空值。

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

代码语言:javascript
复制
$(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);
        };
    }
});
票数 10
EN

Stack Overflow用户

发布于 2018-09-22 22:27:13

建立在此之前的所有答案的基础上,并为其他寻找此问题的人提供参考--在我们的情况下,我们将其追溯到HTTP2协议(注意--我们是在HTTPS上进行测试;我不确定HTTP上是否有问题.)。

  • 当我们在浏览器(或服务器上的IIS )中禁用HTTP2时,AjaxPro调用正常工作。
  • 然而,当使用HTTP2时,响应是普通的"200“,而不是"200 OK",AjaxPro将其解释为失败。
票数 4
EN

Stack Overflow用户

发布于 2014-09-22 19:31:02

对这个问题的提示是

代码语言:javascript
复制
"Message":""

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

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

代码语言:javascript
复制
   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“子句。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25981779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档