怎样终止HTTP请求

使用 xhr.abort()

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://www.example.com/page.php', true);
setTimeout(function () {
  if (xhr) {
    xhr.abort();
    xhr = null;
  }
}, 5000);
xhr.send(null);

注意: xhr.abort() 会直接终止请求, xhr.readyState值变为4, xhr.onreadystatechange事件触发.

原文地址:https://www.cnblogs.com/aisowe/p/11558638.html