jQuery UI 选项卡(通过 ajax 加载)和表单数据的问题
我正在尝试设置一个界面,其中包含一个包含有关某些 jQuery UI 选项卡的过滤器的表单。选项卡通过 ajax 加载。
当我单击其中一个选项卡时,我希望将表单中的数据提交到该选项卡。
我设置了 ajaxOptions 以从表单中获取数据,将其序列化,然后将其 POST 到 url。我已关闭缓存,并且已关闭 ajaxOptions 的缓存。
这是我用来设置选项卡的代码。
$("#schedule-tabs").tabs({
ajaxOptions: {
type: 'POST',
data: $('#filters').serialize(),
cache: false,
error: function(xhr, status, index, anchor) {
$(anchor.hash).html("<p>An error has been encountered while attempting to load this tab.</p>");
}
},
cache: false
});
加载选项卡时,传递的数据是首次加载页面时表单中的数据,即使我更改了表单中的过滤器。
我已将以下内容添加到上述选项卡设置中,以一路验证表单数据:
select: function(event, ui) {
alert($('#filters').serialize());
},
load: function(event, ui){
alert($('#filters').serialize());
},
show: function(event, ui){
alert($('#filters').serialize());
}
在所有 3 个实例中,都会提醒更新的表单数据。但是,当数据到达我的页面时,它是原始数据而不是新数据。
似乎有东西被缓存在某个地方,但我不知道在哪里。
难道不应该为每个 ajax 页面加载从表单中获取新鲜的数据吗?为什么会被缓存?是否有其他方法可以覆盖选项卡内容加载时发布的数据?
这是我当前项目中的一个巨大障碍。如果我不能很快解决它,我将不得不寻找 jQuery UI 选项卡之外的其他解决方案。我想使用它们,但是如果这个问题无法解决......
任何人都可以帮忙吗???
I am attempting to set up an interface that has a form containing filters about some jQuery UI Tabs. The tabs are loaded via ajax.
When I click on one of the tabs, I want the data from the form to be submitted to that tab.
I set up the ajaxOptions to grab the data from my form, serialize it, and POST it to the url. I have caching turned OFF, and I have caching for the ajaxOptions turned OFF.
This is the code I am using to set up the tabs.
$("#schedule-tabs").tabs({
ajaxOptions: {
type: 'POST',
data: $('#filters').serialize(),
cache: false,
error: function(xhr, status, index, anchor) {
$(anchor.hash).html("<p>An error has been encountered while attempting to load this tab.</p>");
}
},
cache: false
});
When the tabs load, the data that is passed along is the data that was in the form when the page was first loaded even though I have changed the filters in the form.
I have added the following to the above tab setup to verify the form data along the way:
select: function(event, ui) {
alert($('#filters').serialize());
},
load: function(event, ui){
alert($('#filters').serialize());
},
show: function(event, ui){
alert($('#filters').serialize());
}
In all 3 instances, the updated form data is alerted. However, when the data reaches my page, it is the original data not the new data.
It appears that something is being cached somewhere, but I have no clue where.
Shouldn't the data be grabbed fresh from the form for each ajax page load? Why is it being cached? Is there some other way that I can override the data that is being posted when the tab content loads?
This is a huge blocker in my current project. If I can't resolve it soon, I will have to find some other solution other than the jQuery UI Tabs. I want to use them, but if this issue can't be resolved ...
Can anyone help???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信我已经找到了自己问题的答案。我想分享以防其他人遇到同样的情况。
基本上,我添加了一个选项,当选择选项卡时,它会获取当前表单数据并重置 ajaxOptions。
我现在使用的代码是:
我希望这对其他人有帮助。
I believe I have figured out the answer to my own question. I wanted to share in case others have run into this same situation.
Basically, I added an option that when a tab is selected, it gets the current form data and resets the ajaxOptions.
The code I am now using is:
I hope this helps someone else out.