jQuery UI 选项卡第一个加载的选项卡被缓存,尽管指定了 ajaxOptions:cache: false
我有一些选项卡,其中每个选项卡都是使用 ajax 加载的。我不想缓存(我希望每次单击选项卡时都发出 ajax 请求)。我创建的选项卡如下:$('#tabs').tabs({ ajaxOptions: { cache: false}, spinner: '正在加载任务...' });
由于上述原因,当我单击选项卡时,附加一个特殊变量:http://localhost:3252/Task/Show/2?_=1327576289684
它通过使 url 唯一来防止缓存,因此请求始终发送到服务器。
但是,当我打开带有选项卡的页面时,它们会被初始化并加载默认选项卡(任务 1)。在这种情况下,不会附加变量:http://localhost:3252/Task/Show/1
这会导致页面从缓存加载。
我通过更改选项卡 url 以包含每个请求的唯一编号(在我的情况下打勾)来更改行为:
@<div id="tabs">
<ul>
@Code
For Each task In Model.Tasks
@<li><a href="@[email protected]"><span>@task.Name (@task.Number)</span></a><span class='ui-icon ui-icon-close'>Remove task</span></li>
Next
End Code
</ul>
@*@Html.EditorFor(Function(m) (m.Tasks))*@
</div>
问题是:为什么我必须这样做?这难道不是您想用ajaxOptions: {cache: false}
来解决的吗?有没有人以前遇到过这个问题并找到了一个很好的解决方案?我错过了什么还是它是一个错误?
I have tabs where every tab is loaded using ajax. I do not want to cache (I want ajax request any time the tab is cliked). I created tabs as following:$('#tabs').tabs({ ajaxOptions: { cache: false}, spinner: 'Loading task...' });
Thanks to the above, when I click on a tab, a special variable is appended:http://localhost:3252/Task/Show/2?_=1327576289684
It prevents prevents caching by making the url unique, so the request is always sent to the server.
However, when I open the page with the tabs, they are initialized and the default tab (Task 1) is loaded. In this case the variable is not appended:http://localhost:3252/Task/Show/1
which consequently causes the page to load from cache.
I changed the behavior by changing the tab url to contain a per request unique number (ticks in my case):
@<div id="tabs">
<ul>
@Code
For Each task In Model.Tasks
@<li><a href="@[email protected]"><span>@task.Name (@task.Number)</span></a><span class='ui-icon ui-icon-close'>Remove task</span></li>
Next
End Code
</ul>
@*@Html.EditorFor(Function(m) (m.Tasks))*@
</div>
The question is: why do I have to do that? Isn't it something that you would like to solve with ajaxOptions: { cache: false}
? Has anyone encountered this problem before and found a nice solution to it? Am I missing something or is it a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将主 jQuery ajax 设置缓存强制设置为 false?您可能需要一个覆盖所有 ajax 请求的默认设置。您可以将其放入准备好的文档中:
供参考的文档: http://api.jquery.com/jQuery .ajax/
Have you tried forcing the main jQuery ajax settings cache to false? It may be that you need a blanket setting as a default that covers all ajax requests. You could place this in your document ready:
Docs for reference: http://api.jquery.com/jQuery.ajax/