日期:2014-05-16  浏览次数:20654 次

Ajax检测用户名问题!!!!!


function createXmlHttp()
{
var xmlHttp;
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e)
{
try
{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e)
{
try
{xmlHttp=new XMLHttpRequest();}catch(e)
{

}

}


}

return xmlHttp;
}




function CheckUser()
{

var xmlHttp=createXmlHttp();
if(xmlHttp==null)
{
alert("您的浏览器不支持Ajax!")
return
}
var user=document.getElementById("user").value;
//alert(xmlHttp);
//var url='display.jsp?user='+user;
xmlHttp.open("GET","display.jsp",true);
xmlHttp.onreadystatechange=disResult()
{
if(xmlHttp.readystate==4)
{
if(xmlHttp.status==200)
{
document.getElementById("display").value=xmlHttp.responseText;

}
}

}
xmlHttp.send(null);

}

 大侠帮我看看吧!!谢谢啦。向display.jsp发的请求没反应啊。。。


------解决方案--------------------
用jquery 或者别的库ajax吧,原生的浏览器写法太折磨人了,
$.get("display.jsp",{user:$("#user").val()},function(data){
alert(data);//这里判断
});

------解决方案--------------------
xmlHttp.onreadystatechange=disResult()
这句,你的disResult函数写了吗?
还有注册回调函数不需要括号,应该是
xmlHttp.onreadystatechange=disResult
------解决方案--------------------
说的对。
探讨
xmlHttp.onreadystatechange=disResult()
这句,你的disResult函数写了吗?
还有注册回调函数不需要括号,应该是
xmlHttp.onreadystatechange=disResult