Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConnectFailure in AjaxPro on certain browsers

This issue has been reproduced on PlayStation 3, 4, Xbox360, Xbox One. This issue is present with all versions of AjaxPro.

When making an Ajax request (using AjaxPro) the server returns the correct content. However, the object returned in the call back function is

{
   "error": 
    {
     "Message":"","Type":"ConnectFailure","Status":200},"value":null,
     "request":
     {
       "method":"MethodName",
       "args":
       {
          "Argument1":"1111","Argument2":"2222"
       }
     },
    "context":null,"duration":18
   }
}
like image 747
Roman Mik Avatar asked Sep 22 '14 19:09

Roman Mik


1 Answers

In my case, I am having this same error when using AjaxPro with https, TLS 1.2, ECDHE_RSA with P-256 key exchange, and AES_256_GCM cipher (IE11+, Chrome51+, Firefox49+. Check yours here). It runs ok with obsolete AES_256_CBC with HMAC-SHA1 cipher.

The problem is that XMLHttpRequest.statusText property is empty after server response (I do not really know why) and AjaxPro.Request.prototype.doStateChange method (ajaxpro/core.ashx file) expected "OK" to take response as valid:

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};
}

I finally decided to override AjaxPro.Request.prototype.doStateChange method and allow an empty value in this.xmlHttp.statusText.

I added this script to my affected pages:

$(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);
        };
    }
});
like image 67
Rafael Neto Avatar answered Sep 28 '22 08:09

Rafael Neto