How to cancel/abort jQuery AJAX request?

后端 未结 8 2131
时光说笑
时光说笑 2020-11-22 09:30

I\'ve an AJAX request which will be made every 5 seconds. But the problem is before the AJAX request if the previous request is not completed I\'ve to abort that request and

8条回答
  •  独厮守ぢ
    2020-11-22 10:06

    I know this might be a little late but i experience similar issues where calling the abort method didnt really aborted the request. instead the browser was still waiting for a response that it never uses. this code resolved that issue.

     try {
            xhr.onreadystatechange = null;
            xhr.abort();
    } catch (e) {}
    

提交回复
热议问题