
const xhr = new XMLHttpRequest();
xhr.open('PUT','http://118.24.84.199:8080/sm/accept/list',false);xhr.setRequestHeader('token','515b8c62-ddf4-41ef-a7c8-93957e1c589e');
xhr.setRequestHeader('Accept','application/json');
xhr.setRequestHeader('Content-Type','application/json');let data = {
page:1,
pageSize:10,
};
data = JSON.stringify(data);
xhr.send(data);
console.log(xhr.response);
xhr.onreadystatechange = function(event){
if (xhr.readyState == 4){
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304){
console.log(JSON.parse(xhr.response));
} else {
console.log("Request was unsuccessful: " + xhr.status);
}
}
};相关文章:
如何用原生JS实现Ajax的GET POST请求
实例讲解使用原生JavaScript处理AJAX请求的方法
相关视频:
Ajax原理详解视频教程
