How to redirect to new page in jquery callback function

I am developing an application using jquery along with servlets. I am using jquery theme roller for the interface. In my Login.jsp

<html>
<head>
<script>
$(document).ready(function() {
$("#dialog").dialog();
}); 
 </script>

  <script>
    $("#submit").click(function(){
    $("#LoginForm").submit(function()
    {
     var username=$("#username").val();
     var password=$("#password").val();
     var datastring='username='+username+ '&password= '+password;

   $.ajax({
   type: "POST",
   url:'Login',
   data: datastring
   error: function(){
            alert("Data Error"); 
        },
        success: function (data){
            window.location.replace("Items.jsp");
        }
     });
    });
});
  </script>

</head>
 <body style="font-size:62.5%;">
<div id="dialog" title="Login">
<form id="LoginForm" method="post">
<fieldset>
<label>Username:</label>
<input type="text" id="username"></input><br></br>
<label>Password:</label>
<input type="password" id="pwd"></input><br></br>
<input type="submit" id="submit" value="Log In" align="middle"></input>
</fieldset>
</form>
</div>

 

The data is passed to the servlet, and as soon as the login is successful, I want the user to be redirected to a new page, for example, Items.jsp. In my callback, I used window.location.replace ("Items.jsp") . I can not redirect.

I tried using response.sendRedirect ("Items.jsp") and return * "Items.jsp" *

But I can not redirect it to a new page. Where am I mistaken.

Thank:)

+3
source share
4 answers

window.location = "items.jsp"?

, ajax "url:".

, .

http://jsfiddle.net/zuSZg/

+1

window.location.href ="Items.jsp"

: window.location MDC

0

Setting window.location to a new URL will change the current web page to the specified location.

window.location = "http://www.stackoverflow.com/"
0
source
Use this :
 $(window.location).attr('href', 'http://www.google.com');
0
source

All Articles