浏览器实现get请求

let url = 'https://www.toutiao';
let params = {

};
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(JSON.stringify(params));

 

 

posted @ 2022-05-20 17:02  淋哥  阅读(781)  评论(0编辑  收藏  举报