[英]jQuery AJAX Page Redirection Error
$.ajax({
url: "NewUserRegistrationServlet",
type: "post",
cache: false,
data : "username="+username+"&password="+encodeURIComponent(pswd)+"&email="+encodeURIComponent(email),
dataType:"xml",
timeout: 3000,
success: function(data) {
var xml_node = $('ResultSet',data);
var status = xml_node.find('result').text() ;
var result = xml_node.find('status').text() ;
if( (result > 0) && ( status == 'SUCCESS') ) {
alert("This Statement is getting executed");
//window.location.replace("login.jsp"); // Not Working
//window.location.href = 'http://localhost:8080/MyProj/login.jsp'; // Not Working
window.open = ('login.jsp','_top'); // Not Working
}else{
$("#RegisErr").siblings("p").remove();
$("#RegisErr").after("<p>User Registration failed! Please Try Again.</p>");
}
},
error: function(xhr, status, text) {
$("#RegisErr").siblings("p").remove();
$("#RegisErr").after("<p>User Registration failed! Please Try Again.</p>");
}
});
我做錯了
編輯
屏幕快照Chrome調試器
解決了
windows.location = "login.jsp"
謝謝大家的幫助。
使您的方法有效,即:
1. window.location.replace("http://stackoverflow.com");
2. window.location.href = "http://stackoverflow.com";
代碼運行后,瀏覽器仍在提交表單。 添加return false; 給處理程序以防止這種情況。
否則,僅使用window.location =“ http://stackoverflow.com ”;
請參閱此帖子( window.location.href不起作用 )以進行進一步的說明。 如果您仍然遇到問題,請再次標記我。 我會為您寫一個詳細的答案。
此注釋是您的解決方案可以使用的代碼-https: //stackoverflow.com/a/6094213/1366216
請從結果中修剪所有空白。 您應該在if塊之前寫以下行。
if(Number(result)>0 && status.trim()==="success")
{
//do anything you want
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.