手写 AJAX

  • 手写ajax
// AJAX
const xhr = new XMLHttpRequest()
xhr.open('GET', '/xxx')
xhr.onreadystatechange = () => {
  if (xhr.readyState === 4) {
    const status = xhr.status
    if (status >= 200 && status < 300 || status === 304) {
      success(xhr)
    } else {
      fail(xhr)
    }
  }
}
xhr.send()
posted @ 2024-06-06 13:54  codejnp  阅读(2)  评论(0编辑  收藏  举报