-
-
Save wdfx100/5562168 to your computer and use it in GitHub Desktop.
#ajax#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createXMLHttpRequest(){ | |
var xmlHttp;//创建ajax引擎 | |
if(window.ActiveXObject){ | |
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
}else{ | |
xmlHttp = new XMLHttpRequest(); | |
} | |
return xmlHttp; | |
} | |
//()有,返回的是值,无 返回的是函数 | |
document.getElementById("nickname").onblur=function(){ | |
var xmlHttp = createXMLHttpRequest(); | |
var nickname = document.getElementById("nickname").value; | |
xmlHttp.open("get","/ajax.do?nickname="+nickname,true); | |
//设置回调函数,接受服务器传过来的值 | |
xmlHttp.onreadystatechange=function(){ | |
if(xmlHttp.readyState==4){ | |
if(xmlHttp.status=200){ | |
var value = xmlHttp.responseText; | |
if(value=="yes"){ | |
document.getElementById("msg").innerHTML="√"; | |
}else{ | |
document.getElementById("msg").innerHTML="该昵称被占用"; | |
} | |
}else{ | |
alert("服务器忙"); | |
} | |
} | |
}; | |
xmlHttp.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment