var xhr = new XMLHttpRequest(); //创建XHR对象
//监听XHR对象的状态改变事件
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
};
//打开到服务器的连接
xhr.open(‘post’, gDatagridUrl, true);
xhr.setRequestHeader(“Authorization”, sessionStorage.getItem(“token”));
xhr.setRequestHeader(“Content-Type”, “application/json”);
xhr.setRequestHeader(“Accept”, “application/json”);
//注册回调函数
// xhr.onload = function () {
// if (this.status == 200) {
// var res = this.response;
// console.log(res)
// }
// };
//发起请求消息
xhr.send();
原生js请求
最新推荐文章于 2024-07-16 11:07:42 发布