var xhr = new XMLHttpRequest();
1 xhr.open("GET","demo.asp?t=" + Math.random(),true); 2 xhr.send();
1 xhr.open("GET","demo.asp",true); 2 xhr.setRequestHeader("If-Modified-Since","0"); //設置瀏覽器不使用緩存 3 xhr.send();
1 xhr.open("POST","postdemo.asp",true); 2 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //不然數據沒法被正常接收 3 xhr.send("name=amie"); //send裏寫要發送的數據
1 xhr.onreadystatechange = function () { 2 if (xhr.readyState == 4 && xhr.status == 200) { 3 console.log(xhr.responseText); 4 };
(寫在結尾:前端新人一枚~歡迎你們指出錯誤,謝謝閱覽~)html
【轉發自http://www.cnblogs.com/YiminLiu/p/6078987.html】前端