admin管理员组

文章数量:1535059

 需要的代码如下(注意修改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);
};

 

 

本文标签: 如何用浏览器测试post