ajax实现登陆验证
js文件如下:
var xmlHttp;
function IMG1_onclick() {
CheckIsValid();
}
function CheckIsValid()
{
CreatXmlHttpRequest();
var userName=document.getElementById("AdminText");
var passWord=document.getElementById("AdminPasswordText");
var url="CheckLogin.aspx?userName="+escape(userName.value)+"&passWord="+escape(passWord.value);
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=callback;
xmlHttp.send(null);
}
function CreatXmlHttpRequest()
{
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != ''undefined'') {
xmlHttp = new XMLHttpRequest();
}
}
function callback()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var mes=xmlHttp.responseXML.getElementsByTagName("message")[0].firstChild.data;
var val=xmlHttp.responseXML.getElementsByTagName("passed")[0].firstChild.data;
setMessage(mes,val);
}
}
}
时间: 2024-10-13 18:13:42