返回列表

队列请求XHR

默认分类 2020/03/25 00:51

代码如下:

var wlist=[
'abide',
'acculturate',
'address',
'annul',
'arbitrage'
]

var f200 = []
var f404 = []
var createXHR = function (ww, callback) {
  let xhr = new XMLHttpRequest()

  var url = 'https://www.macmillandictionary.com/dictionary/british/' + ww
  xhr.open("get", url)
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

  xhr.onreadystatechange = () => {
    if (xhr.readyState !== 4) return ''
    const status = xhr.status;
    if (status == 200) {
      f200.push(url)
      // page.saveData(xhr.responseText)
    } else {
      console.log(curIndex + ': File occur error');
      f404.push(url)
    }
    callback()
  }
  xhr.send()
}

function run(){ var w=wlist.pop();if(!w) return ''; createXHR(w, function(){run()})}


>> 留言评论