简单封装一个AJAX
function myAxios(method, url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
resolve(xhr.responseText)
} else {
reject('error')
}
}
}
xhr.open(method, url, true)
xhr.send()
})
}