前端请求
XMLHttpRequest
//XMLHttpRequest.UNSENT
//XMLHttpRequest.OPENED
//XMLHttpRequest.HEADERS_RECEIVED
//XMLHttpRequest.LOADING
//XMLHttpRequest.DONE
let xhr
if (window.XMLHttpRequest) {
// Mozilla, Safari...
xhr = new XMLHttpRequest()
} else if (window.ActiveXObject) {
// IE
try {
xhr = new ActiveXObject('Msxml2.XMLHTTP')
} catch (e) {
try {
xhr = new ActiveXObject('Microsoft.XMLHTTP')
} catch (e) {}
}
}
if (xhr) {
xhr.onreadystatechange = function onReadyStateChange() {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log('执行成功')
} else {
console.log('执行出错')
}
}
xhr.open('POST', '/api', true)
// 以表单的形式传递数据
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
xhr.send('username=admin&password=root')
}JQuery Ajax
Fetch
Axios
多请求串行
多请求并行
Last updated