0
点赞
收藏
分享

微信扫一扫

利用浏览器控制台进行网络请求

MaxWen 2022-04-21 阅读 84
javascript

var url = "http://127.0.0.1:8080/open/test";
var params = {
    "ids": [11]
};
var xhr = new XMLHttpRequest();
xhr.open("POST", 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));

举报

相关推荐

0 条评论