F12打开Console输入以下代码:
POST请求
var url = "http://ip地址:8080/test/?id=26323";
var params = {"billIds":["56141305725718528"],"billType":"VBNSC"};
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.send(JSON.stringify(params));
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
GET请求
var url = "http://IP:8080/testGet?id=235";
var 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.send();
xhr.onerror = function (e) {
console.error(xhr.statusText);
};