2014-10-07 130 views
1
$.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>"); 
       } 
      }); 

我在做什麼錯誤jQuery的AJAX頁面重定向錯誤

  1. 的OnSubmit - >確認形式的//工作正常
  2. 如果合法 - >做Ajax請求//工作精細
  3. 關於Ajax的成功 - >重定向到其他JSP頁面//不要催眠

編輯

截圖Chrome的調試 enter image description here

解決

windows.location = "login.jsp" 

謝謝大家對你的幫助。

+0

你得到哪些錯誤? – 2014-10-07 07:28:51

+0

也許'NewUserRegistrationServlet'中缺少擴展文件... ??? – Xlander 2014-10-07 07:29:28

+0

@PhilippM它不是重定向login.jsp頁面? – KumarDharm 2014-10-07 07:32:55

回答

1

爲了使您的工作方法,即之一: -

1. window.location.replace("http://stackoverflow.com"); 
2. window.location.href = "http://stackoverflow.com"; 

瀏覽器仍然在提交表格的代碼運行之後。 添加返回false;給處理程序以防止這種情況。

否則,只使用window.location =「http://stackoverflow.com」;

請參閱此帖子(window.location.href not working)以獲得進一步的說明。如果您仍然遇到問題,請再次標記我。我會爲你寫一個詳細的答案。

此言代碼爲您的解決方案的工作 - https://stackoverflow.com/a/6094213/1366216

0

請修剪結果中的所有空格。如果block之前你應該寫下面的行。

if(Number(result)>0 && status.trim()==="success") {

//do anything you want 

} 
+0

如果條件得到執行檢查編輯代碼。 – KumarDharm 2014-10-07 07:36:02

+0

我可以知道你在控制檯中得到了什麼錯誤嗎? – Amy 2014-10-07 07:36:47

+0

Amol在控制檯上沒有錯誤,我用Firebug進行調試。 '_self'也不起作用。 – KumarDharm 2014-10-07 07:41:20