Skip to content

Instantly share code, notes, and snippets.

@wdfx100
Created May 12, 2013 02:26
Show Gist options
  • Save wdfx100/5562168 to your computer and use it in GitHub Desktop.
Save wdfx100/5562168 to your computer and use it in GitHub Desktop.
#ajax#
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