function checkUsername(){緩存
// 得到文件框值:異步
var username = document.getElementById("username").value;ide
// 1.建立異步交互對象spa
var xhr = createXmlHttp();xml
// 2.設置監聽對象
xhr.onreadystatechange = function(){get
if(xhr.readyState == 4){it
if(xhr.status == 200){io
document.getElementById("span1").innerHTML = xhr.responseText;function
}
}
}
// 3.打開鏈接(防止緩存)
xhr.open("GET","${pageContext.request.contextPath}/user_findByName.action?time="+new Date().getTime()+"&username="+username,true);
// 4.發送
xhr.send(null);
}
//建立異步請求對象
function createXmlHttp(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{// Internet Explorer
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return xmlHttp;
}