方法一
const ajax = (method, url, data, success, fail) => {
var request = new XMLHttpRequest()
request.open(method, url)
request.onreadystatechange = function() {
if(request.readyState === 4) {
if(request.status >= 200 && request.status < 300 || request.status === 304) {
success(request)
} else {
fail(request)
}
}
}
request.send(data)
}
方法二
const ajax = (method, url, data, success, fail) => {
var request = new XMLHttpRequest()
request.open(method, url)
request.onload = function(){
if(request.status >= 200 && request.status < 300 || request.status === 304) {
success(request)
} else {
fail(request)
}
}
request.send(data)
}