你的位置:首页 > Java教程

[Java教程]原生js版ajax请求


  1. function get
  2.           var xhr;  
  3.           if(window.ActiveXObject) {  
  4.                    xhr= new ActiveXObject("Microsoft.
  5.           }else if (window.
  6.                    xhr= new 
  7.           }else {  
  8.                    xhr= null;  
  9.           }  
  10.           return xhr;  
  11. }  
  12.   
  13. function save() {  
  14.           var xhr = get
  15.           xhr.open("post","url");  
  16.           var data = "name=mikan&address=street...";  
  17.           xhr.send(data);  
  18.           xhr.onreadystatechange= function() {  
  19.                    if(xhr.readyState == 4 && xhr.status == 200) {  
  20.                             alert("returned:"+ xhr.responseText);  
  21.                    }  
  22.           };