JS-Web-API(三):Ajax

XMLHttpRequest

GET请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 初始化实例
const xhr = new XMLHttpRequest()
// 第三个参数true则为异步
xhr.open('GET','url', true)
xhr.onreadystatechange = function () {
// 这里函数异步执行
if (xhr.readyState === 4) {
if (xhr.statusCode === 200) {
console.log(xhr.responseText)
} else {
console.log('请求失败')
}
}
}
xhr.send()
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×