通过XMLHttpRequest实现Ajax无刷新处理数据

function checktel(str) {  
     xmlhttp = null;  
     if(window.XMLHttpRequest){//other 浏览器  
         xmlhttp = new XMLHttpRequest();  
     }  
     else if(window.ActiveXObject){//ie5 6  
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
     }  
     if(xmlhttp != null){  
         xmlhttp.onreadystatechange=function(){//当页面改变状态时执行此方法  
             if(xmlhttp.readyState==4 && xmlhttp.status==200){  
                 document.getElementById("txtHint").innerHTML = xmlhttp.responseText;  
            }  
         }  
         xmlhttp.open("POST","p.php?tel=dd",true);  
         xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312;");//GET传递时可以省略  
         xmlhttp.send(str=' + str);  
     }  
 } 

后台通过post 或get接收参数.

posted on 2011-05-09 14:57  dawnruby  阅读(318)  评论(0)    收藏  举报

导航