ajax做异步提交用户信息,怎么页面还是会刷新呢?
//创建xmlHttp浏览器对象
var xmlHttp;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
if(!xmlHttp)
{
window.alert('不能创建XMLHttpRequest对象实例!');
return false;
}
}
}
}
}
//注册回调函数
function showReg()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="true")
{
alert('注册成功!');
}
else if(xmlHttp.responseText=="false")
{
alert('注册失败!');
}
else
{
alert('都没执行!');
}
}
}
}
//注册主调函数
function Reg()
{
createXMLHttpRequest();
var url= "post.aspx?Uname="+document.getElementById("Uname").value+"&Upwd="+document.getElementById("Upwd").value+"&Usex="+document.getElementById("sex").value+"&Event=reg";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=showReg;
xmlHttp.send(null);
}
//检查注册用户是否存在回调函数
function checkUser()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="true")
{
document.getElementById("img").src="images/false.gif";
document.getElementById("BTreg").disabled=true;
}
else if(xmlHttp.responseText=="false")
{
document.getElementById("img").src="images/true.gif";
document.getElementById("BTreg").disabled=false;
}
else
{
alert('都没执行!');
}
}
}
}
//检查注册用户是否存在主调函数
function selectUser()
{
createXMLHttpRequest();
var url= "post.aspx?Uname="+document.getElementById("Uname").value+"&Event=checkUser";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=checkUser;
xmlHttp.send(null);
}
//传参数出问题
function postEorror()
{
if(xmlHttp.responseText=="End")
{
return false;
}
}