除去过去所学会的,今天又有了很多的收获,比起以前,这次写ajax容易多了,也很轻松~!
var xmlHttpRequest;
function creatXmlHttp(){
if(window.ActiveXObject)
{
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttpRequest=new XMLHttpRequest();
}
}
-----------------------
function checkuser(){
creatXmlHttp();
var name=document.all("user").value;
xmlHttpRequest.onreadystatechange=function(){
if (xmlHttpRequest.readyState==4){
if (xmlHttpRequest.status==200){
result=xmlHttpRequest.responseText;
if (result=="true"){
document.getElementById("right").style.display="block";
document.getElementById("wrong").style.display="none";
}else{
document.getElementById("right").style.display="none";
document.getElementById("wrong").style.display="block";
}
}else{
window.status="验证码检验失败,请联系管理员!";
}
}else{
window.status="正在进行验证码检验...";
}
}
xmlHttpRequest.open("post","/ajaxjson/ajax.do?name="+name,true);//true 异步 false 同步
xmlHttpRequest.send();------------------ 早在一起,不喜欢按规范写,有时候不用这个xmlHttpRequest.onreadystatechange,喜欢直接在
xmlHttpRequest.send(); 后面直接写
result=xmlHttpRequest.responseText; 以前没有发现什么错误。可是今天调试了老半天,都说我网页错误,一查总是这个 result=xmlHttpRequest.responseText 错误~! 好无奈了~!
----------------学到~--以前怎么不出同步问题呢?? 不过还是按规范吧。毕竟这个方法自有其妙用------受教--}