建立AJax代码记录

<script type="text/javascript"> var xmlHttp; function createXMLHttpRequest(){ //识别浏览器类型  建立一个 xmlHttp对象 if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (ex) { try { xmlHttp = new ActiveXObject("Mirosoft.XMLHTTP"); } catch (ex) { } } } } //调用此方法 function sendMessage(){   if(xmlHttp == null){   createXMLHttpRequest();   }   var username = document.getElementById("username").value;     //指定请求的属性   xmlHttp.open("POST","TestAjax?username="+username,true);   //指定回调函数   xmlHttp.onreadystatechange = callback;   //执行发送   xmlHttp.send(null);   }     //回调函数   function callback(){   //服务器返回成功   if(xmlHttp.status == 200 && xmlHttp.readyState == 4){   //服务器返回结果   var text = xmlHttp.responseText;     var mydiv=document.getElementById("mydiv"); mydiv.innerHTML=text;   }   } </script>
相关文章
相关标签/搜索