Ajax不起作用啊!!求大神解答
function fun(){
var req=null;
if(window.XMLHttpRequest){
req=new XMLHttpRequest();
}else{
req=new AcitveXObject("Msxml2.XMLHTTP");
}
alert("aaa");
req.open("post","servlet/UserServlet?method=ajax");
alert("bbb");
req.onreadystatechange = function(){
if(req.readyState==4 && req.status == 200){
alert("ccc");
if(req.responseText>0){
alert("用户名已经存在");
}else if(req.responseText=-2){
alert("bunengweik");
}
}
alert("ddd")
}
alert("eee")
req.setRequestHeader("content-type"," application/x-www-form-urlencoded");
var txt = document.getElementById("username");
req.send("name=" + txt.value);
}
只能弹出aaa bbb eee 怎么回事啊