2014-10-07 600 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