document.location()
logn.js
中給出的函數在Internet Explorer中正常工作,但在Firefox中不起作用。給定的js代碼是用於在登錄頁面中實現AJAX的。AJAX將代碼指向一個servlet,如果登錄成功,則將用戶登錄作爲響應。.js代碼中給出的document.location()函數在Internet Explorer中正常工作,但在Firefox中不起作用
logn.js
function logn(emailId,password) {
var parameters="emailId="+emailId+"&password="+password;
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if(xmlhttp.responseText.toString()=="User Login") {
document.location("userhome.jsp");
} else if(xmlhttp.responseText.toString()=="Admin Login") {
document.location("adminhome.jsp");
}else {
//document.getElementById("message").innerHTML = xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}
};
xmlhttp.open("POST", "LoginServlet", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(parameters);
}
以下是servlet代碼LoginServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
String emailId=request.getParameter("emailId");
String password=request.getParameter("password");
if (emailId.isEmpty()||password.isEmpty()) {
out.write("Please enter EmailId/Password");
} else {
LoginModel lm=new LoginModel();
lm.setEmailId(emailId);
lm.setPassword(password);
LoginService ls=new LoginService();
lm=(LoginModel) ls.loginCheck(lm);
if(lm!=null){
System.out.println("login ok");
HttpSession session =request.getSession();
System.out.println(lm.getLoginId());
session.setAttribute("userlogin", lm);
if (lm.getIsAdmin()==0) {
System.out.println("aaaaaaaaaaa");
out.write("User Login");
}
else if (lm.getIsAdmin()==1)
out.write("Admin Login");
ls.setIsActive(lm.getLoginId(),1);
} else
out.write("Wrong EmailId/Password");
}
}
你已經安裝在Firefox螢火所以看到什麼錯誤發生? – peroija 2012-03-04 19:13:49