weixin_33724570 2018-03-16 13:02 采纳率: 0%
浏览 12

Ajax通话被取消

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料