>[success] # 原生写法 >[danger] ##### GET 写法 ~~~ function Ajax2() { //创建对象 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if(xhr.readyState==4){ console.log((xhr.responseText)); } } //获取数据 xhr.open('GET','/ajax?p=123'); xhr.send(null); }; ~~~ >[danger] ##### POST 写法 ~~~ function Ajax3() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if(xhr.readyState==4){ //接受服务器返回的数据 console.log(xhr.responseText); } } xhr.open('POST','/ajax/'); //post 请求头 xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset-UTF-8') //post 请求发送参数d xhr.send("p=456"); } ~~~