手写 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()