1 var xhr = new XMLHttpRequest(); 2 xhr.onreadystatechange = function(){ 3 if(xhr.readyState == 4){ 4 if((xhr.status >= 200 && xhr.status <= 300) || xhr.status == 304){ 5 alert(xhr.responseText); 6 }else{ 7 alert("Request was unsuccessful:" + xhr.status); 8 } 9 } 10 //get 11 xhr.open("get", "example.php", true); 12 xhr.setRequestHeader("MyHeader", "MyValue"); 13 xhr.send(null); 14 //post 15 // xhr.open("post", "postexample.php", true); 16 // xhr.setRequestHeader("Content-Type", "applicatoin/x-www-form-urlencoded"); 17 // var form = document.getElementById("user-info"); 18 // xhr.send(serialize(form)); 19 };