浏览器测试post请求看大神是怎么做的
需要的代码如下(注意修改url和参数):var url = "http://localhost:7788/user/save";
var params = {"name":"zhangsan","id":1,"age":16,"address":"南京"}; //此为json格式的参数
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);
};
页:
[1]