如何在jQuery回调函数中重定向到新页面 [英] How to redirect to a new page in jquery callback function

查看:124
本文介绍了如何在jQuery回调函数中重定向到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery和servlet开发一个应用程序.我一直在使用Login.jsp接口中的jQuery主题滚子

I am developing an application using jquery along with servlets.I have been using jquery theme roller for 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>

数据正在传递到servlet,一旦成功登录,我希望用户重定向到一个新页面,例如Items.jsp.在我的回调中,我使用了 window.location.replace("Items.jsp").我无法重定向.

The data is being passed to the servlet and once the login is successful i want the user to be redirect to a new page say Items.jsp. In my callback I have used window.location.replace("Items.jsp").I am not able to redirect.

我尝试了 response.sendRedirect("Items.jsp"),并返回* "Items.jsp" *

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

但是无法将其重定向到新页面.我错了.

But am Not able to Redirect it to a new page.Where I am goin wrong..

谢谢:)

推荐答案

您尝试过window.location = "items.jsp"吗?

编辑

我看到您在ajax调用中缺少"url:"参数.

I see you are missing a "url:" parameter in your ajax call.

在这里查看我的示例.

http://jsfiddle.net/zuSZg/

这篇关于如何在jQuery回调函数中重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆