返回列表

request 函数

默认分类 2019/08/28 06:32

代码如下:

function createXHR(url) {
  let xhr = new XMLHttpRequest()
  xhr.open('GET', url, true)
  xhr.send()
}

代码如下:

function createLink(src) {
  var style = document.createElement('link');style.rel = 'stylesheet';style.type = 'text/css';
  style.href = src;
  document.getElementsByTagName('HEAD').item(0).appendChild(style);
}
var list = document.querySelectorAll('.wordbook-wordlist-name')
list.forEach(it=>{ for(let i = 0; ++i < 12; ) { createLink(it.children[0].href + '?page=' + i); } })

HEAD请求:

function createXHR(url) {
  let xhr = new XMLHttpRequest()
  xhr.open('HEAD', url, true)
  xhr.onreadystatechange = () => {
    if (xhr.readyState !== 4) return ''
    const status = xhr.status;
    if (status == 404) {
      console.log('File not exist');
    }
  }
  xhr.send()
}


>> 留言评论