const xhr = new XMLHttpRequest()
xhr.open('GET', '/api', false)
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText)
}
}
}
xhr.send(null)
const xhr = new XMLHttpRequest()
xhr.open('POST', '/login', false)
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText)
}
}
}
const params = {
userName: '',
password: ''
}
xhr.send(JSON.stringify(params))
值 | 状态 | 描述 |
---|---|---|
0 | UNSENT (未打开) | 表示已创建 XHR 对象,open() 方法还未被调用 |
1 | OPENED (未发送) | open() 方法已被成功调用,send() 方法还未被调用 |
2 | HEADERS_RECEIVED (已获取响应头) | send() 方法已经被调用,响应头和响应状态已经返回 |
3 | LOADING (正在下载响应体) | 响应体下载中,responseText中已经获取了部分数据 |
4 | DONE (请求完成) | 整个请求过程已经完毕 |
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。