Jquery UI 选项卡和 spring mvc
我现在对 javascript 不太了解,但在网上发现了 jquery ui 选项卡并想尝试一下。
然而,当我在一个选项卡中有一个将信息发送到后端的表单时,它们是开箱即用的。响应(从 spring mvc 控制器发送回)无法返回到同一位置。结果是进入没有选项卡的页面,或者将其自身定位在选项卡内容的末尾。
有什么我需要做的吗?
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
});
<ul>
<li><a href="/home/"><span>Home</span></a></li>
<li><a href="/admin/"><span>Admin</span></a></li>
<li><a href="/support/"><span>Support</span></a></li>
</ul>
I do not really now much about javascript but found on the web the jquery ui tabs and wanted to give it a try.
They work out of the box however when I have within one tab a form that send information to the back end. The response (sent back from an spring mvc controller) is unable to come back to the same location. As a result is gone to a page without tabs or it position it self at the end of the tab content.
is there somethin I need to do?
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
});
<ul>
<li><a href="/home/"><span>Home</span></a></li>
<li><a href="/admin/"><span>Admin</span></a></li>
<li><a href="/support/"><span>Support</span></a></li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定使用 ajax 在选项卡中发送表单吗?如果您不使用ajax而只是发送表单,则浏览器将返回的页面替换当前页面是正常的。您需要 ajax 将更新的内容放置在当前选项卡中。
你必须以这种方式发送表单(例如使用 jquery,我还没有测试过它,抱歉,如果有任何拼写错误):
以及发送和接收响应的 javascript:
Are you sure you are using ajax to send the form in the tab? If you don't use ajax and you just send the form it's normal that the browser puts the returned page substituting the current one. You need ajax to place updated content in the current tab.
You have to send the form in this way (for example with jquery, I haven't tested it, sorry if there is any misspelling):
and the javascript to send and receive the response: