手动Js——Ajax
- <script type="text/javascript">
- var xmlHttpReq;
- //创建XMLHTTP对象
- function createXMLHttpRequest(){
- if(window.ActiveXObject){
- xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
- }else{
- xmlHttpReq = new XMLHttpRequest();
- }
- }
- //检查用户
- function checkUser(){
- createXMLHttpRequest();
- var userName =document.getElementById("userName").value;
- var password =document.getElementById("password").value;
- //处理检查的地址
- var url="checkUser.jsp?userName="+userName+"&password="+password;
- xmlHttpReq.open("GET",url,true);
- xmlHttpReq.onreadystatechange = showResult;//showResult是当onreadystatechange的值改变时触发的javascript函数
- xmlHttpReq.send();
- }
- function showResult(){
- if(xmlHttpReq.readyState == 4){
- if(xmlHttpReq.status == 200){
- var result = xmlHttpReq.responseText;//将响应信息作为字符串返回
- //alert( result);
- var checkResult = document.getElementById("checkResult").innerHTML="<b>"+result+"</b>";
- //var b=document.createElement("b");
- //var resultContent = document.createTextNode(result);
- // b.appendChild(resultContent);
- // checkResult.appendChild(b);
- }
- }
- }
- </script>
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlHttpReq.onreadystatechange = ReturnData;
//xmlHttpReq.open("GET", "GetData.aspx?Type=UserRegister&PetName="+PetName+"&Password="+Password+"&Password2="+Password2,"", false);
xmlHttpReq.open("GET", "GetData.aspx?Type=UserRegister&PetName="+PetName,"", false);
xmlHttpReq.send();
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlHttpReq.onreadystatechange = function(){
if(xmlHttpReq.readystate == 4 && xmlHttpReq.status == 200)
{
document.getElementById('checkResult').innerHTML=xmlHttpReq.responseText;
};
xmlHttpReq.open("GET", "GetData.aspx?Type=UserRegister&PetName="+PetName,"", false); xmlHttpReq.send();