如何在jquery回调函数中重定向到新页面
我正在使用jquery和servlets一起开发一个应用程序。我一直在使用jquery主题roll for interface在我的Login.jsp中
$(document).ready(function() { $("#dialog").dialog(); }); $("#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"); } }); }); });
数据被传递给servlet,一旦登录成功,我希望用户重定向到一个新的页面,例如Items.jsp。 在我的回调中,我使用了window.location.replace(“Items.jsp”) 。我无法重定向。
我尝试使用response.sendRedirect(“Items.jsp”)并返回* “Items.jsp”*
但我无法将其重定向到新的页面。我在哪里做错了..
谢谢:)
你试过window.location = "items.jsp"
吗?
编辑
我发现你在ajax调用中缺少一个“url:”参数。
看看我的例子在哪里有效。
试试window.location.href ="Items.jsp"
来源: window.location MDC
将window.location设置为新URL会将当前网页更改为指定位置。
window.location = "http://www.stackoverflow.com/"
Use this : $(window.location).attr('href', 'http://www.google.com');