// 1. 初始化
let xhr = new XMLHttpRequest();
// 2. 设置请求行
let method = "GET"
let url = "http://121.199.29.84:8001/carousel/findAll"
xhr.open(method,url)
// 3. 设置请求头
let token = ""
xhr.setRequestHeader('Authorization',token)
// 4. 设置请求体,并发送请求
xhr.send()
// 5. 监听响应
xhr.onreadystatechange = function(){
if(this.readyState === 4){
if(this.status === 200){
let response = JSON.parse(this.response)
console.log('success:',response);
} else {
console.log('error:',this.response);
}
}
}
ajax使用方法
最新推荐文章于 2024-07-26 20:46:33 发布