在做页面开发时要用到后台的接口,为了方便起见我使用了json-server免去了再去写后台接口,(想要了解json-server的这里附上GitHub地址https://github.com/typicode/json-server/blob/master/README.md)这里只详细说明向json-server发送post请求方式
这里用的ajax发的请求
1,keyValue
var xhr = new XMLHttpRequest();
xhr.open("post","http://localhost:3000/posts/");
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.οnlοad=function () {
console.log("执行完毕");
console.log(xhr.responseText);
}
xhr.send("id="+id+"&name="+name+"&age="+age);