使用AJAX的返回值跟字符串进行比较,无论返回的结果是否与字符串相同都是false问题出在var txt = new String(xhr.responseText);				//获得一个 xml dom 对象。				if("no"==txt1){					alert("no");				}else{					alert("yes");				}				//dom 操作、更新页面			}下面是具体的代码function query(){		var xhr = getXmlHttpRequest();		xhr.open('post','servlet/RegistAction',true);		//必须添加一个消息头 content-type 		xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");		xhr.onreadystatechange=function(){			//编写相应的处理代码			if(xhr.readyState == 4){				//只有 readyState 等亍 4,xhr 才完整地接收到了服务器返回的数据。				//获得文本数据				var txt = new String(xhr.responseText);				//获得一个 xml dom 对象。				if("no"==txt1){					alert("no");				}else{					alert("yes");				}				//dom 操作、更新页面			}		};		xhr.send('username='+document.getElementById("username").value);	}
                    
                    
                添加回答
举报
0/150
	提交
		取消
	
 
                    