Spring MVC 重定向:新页面在 div 中打开
这是我遇到的一个问题。
我有一个jsp页面,它有一个javascript openForm函数。该函数从与dialog.jsp 相关的服务器URL 获取数据,并将该代码插入到我的页面正文中。即,它看起来
function showDialog(url){
$.get(url,function(data){
$("body").append(data);
})
}
不错,但是在用户处理该对话框之后,我想将他重定向到一些更好的地方。我在控制器中使用 return createRedirectModelAndView(URL_CONSTANT) ,负责处理来自该对话框的 POST。
它可以工作,但有一个问题:在该对话框 div 内打开一个新页面(重定向目标)。因此,父页面(用户在其上单击 showDialog)仍然存在,并且看起来重定向正在对话框内重定向用户。这种效果在某些情况下可能很酷,但在我的情况下却不是。我想要完全重定向 - 关闭该页面并打开另一个页面。
我哪里出错了?
Here is a problem I have encountered.
I have jsp page which has a javascript openForm function. This function fetches data from server URL that relates to dialog.jsp and inserts that code into the body of my page. I.e. it looks like
function showDialog(url){
$.get(url,function(data){
$("body").append(data);
})
}
OK, but after user deals with that dialog I want to redirect him to some better place. I use return createRedirectModelAndView(URL_CONSTANT) in the controller, responsible for handling POST from that dialog.
It works, but here is a problem: a new page (redirect target) is opened INSIDE that dialog div. So the parent page (on which user clicks showDialog) still exists and it looks like the redirect is redirecting user inside dialog. This effect can be cool in some situations, but not in mine. I want total redirect - close that page and open another.
Where I went wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想从 Ajax 调用进行重定向,那么您应该从服务器返回重定向 URL,并从 JavaScript 进行重定向/位置更改。
If you want to redirect from an Ajax call then you should return the redirect URL from the server and do the redirect/location change from JavaScript.