0

This issue is literally driving me mad and I've already spent hours researching possible solutions :)

My problem is: I've got a script that, upon loading, makes some AJAX calls to the server. This script is a widget and is already configured for cross-domain , etc.

Everything was working fine until now when 1 request has stopped working. The crazy thing is that is only that one, the others work just fine.

You can see in the screenshot below: enter image description here

This is the code I use to send AJAX requests:

ajax: {
  xhr: null,
  request: function (url, method, data, success, failure){
    if (!this.xhr){
      this.xhr = window.ActiveX ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
    }
    var self = this.xhr;

    self.onreadystatechange = function () {
      if (self.readyState === 4 && self.status === 200){
        success(JSON.parse(self.responseText));
      } else if (self.readyState === 4) { // something went wrong but complete
        if (failure) {
          failure();
        } else { console.error("Ajax calls has failed."); }
      }
    };
    self.onerror = function() {
      if (failure) {
        failure();
      } else { console.error("Ajax calls has failed."); }
    };
    this.xhr.open(method,url,true);
    this.xhr.setRequestHeader('Content-Type', 'application/json');
    this.xhr.send(JSON.stringify(data));
  }
}

And this is the call that causes the problem:

this.ajax.request(
  this.getWidgetUrl() +"/check_referral_code",
  "POST",
  {uuid: SL.uuid, ref_code: ref},
  function(data) {
    if (data.response == "ok") {
      // Do something
    } else {
      console.error(data.message);
    }
  },
  function(data) {
    console.error(data.message);
  }
);

Can anybody help here?

UPDATE: The problem seems to be intermittent. If I reload the page it will literally happen 50% of the times

Manuel Frigerio
  • 181
  • 3
  • 10
  • 1
    https://stackoverflow.com/questions/12009423/what-does-status-canceled-for-a-resource-mean-in-chrome-developer-tools - This url speaks about all the possible scenarios where request can get cancelled. Just check with this. – Luke P. Issac Mar 16 '18 at 13:11
  • Thanks @LukeP.Issac but I can't really see the solution... :/ – Manuel Frigerio Mar 16 '18 at 13:17
  • The problem seems to be intermittent. If I reload the page it will literally happen 50% of the times – Manuel Frigerio Mar 16 '18 at 13:19
  • Are you playing around with iframes somewhere ??? – Luke P. Issac Mar 16 '18 at 13:20
  • Nope, no iframes. However I think I'm getting closer. If i disable the other scripts, it works fine. It seems that the problem is that the other scripts "interrupt" the first one. I''m not sure why though. I thought you could have multiple AJAX calls at the same time (even to the same server)? – Manuel Frigerio Mar 16 '18 at 14:19
  • In my case, Chrome reported the request Canceled. Finally found that the requests were stalling in the browser for longer than the timeout setting so jQuery was cancelling before even making the calls. (The stall time is included in the total calculation for timeout: https://github.com/jquery/jquery/issues/4286) – peater Mar 28 '19 at 18:09

0 Answers0