admin管理员组文章数量:1323348
I use JQuery UI Tabs. What I do is load the content of each tab with Ajax as it is suggested here:
Problem: If the user clicks on Tab A, then Tab B and then Tab A again, the content of Tab A is loaded twice.
Is it possible to cache the content of the JQuery UI Tabs?
I use JQuery UI Tabs. What I do is load the content of each tab with Ajax as it is suggested here: http://jqueryui./tabs/#ajax
Problem: If the user clicks on Tab A, then Tab B and then Tab A again, the content of Tab A is loaded twice.
Is it possible to cache the content of the JQuery UI Tabs?
Share Improve this question asked Oct 31, 2013 at 16:41 MichaelMichael 33.3k50 gold badges223 silver badges374 bronze badges 2- What's the exact AJAX code you are using? Unless you save the contents of the tab in your client side script, whenever they switch the AJAX request will always fire. Without seeing the exact code it is hard to tell whether the AJAX request is being properly cached or not. – thatidiotguy Commented Oct 31, 2013 at 16:46
-
should be possible for
GET
withsame URL
. – Murali Murugesan Commented Oct 31, 2013 at 16:46
3 Answers
Reset to default 6Try using the beforeLoad
event:
$(".selector").tabs({
beforeLoad: function(event, ui) {
// if the target panel is empty, return true
return ui.panel.html() == "";
}
});
beforeLoad( event, ui )
Triggered when a remote tab is about to be loaded, after the beforeActivate event. Can be canceled to prevent the tab panel from loading content; though the panel will still be activated. This event is triggered just before the Ajax request is made, so modifications can be made to ui.jqXHR and ui.ajaxSettings.
Note: Although ui.ajaxSettings is provided and can be modified, some of these settings have already been processed by jQuery. For example, prefilters have been applied, data has been processed, and type has been determined. The beforeLoad event occurs at the same time, and therefore has the same restrictions, as the beforeSend callback from jQuery.ajax().
I have e across this before.
Add a timestamp to the server side url. This way each time the page is reloaded and the server is contacted, there is a new timestamp. But when you are clicking around on the client side, IE doesn't reload the url since it is the same and only changes on page reloads/navigating away and back.
php:
$time = time();
$tabs = "<div id='tabs'>
<ul>
<li><a href='Home.php?viewIsActive=true&tab=true&timeStamp=" . $time . "'> Active </a></li>
<li><a href='Home.php?listAll=true&tab=true&timeStamp=" . $time . "'> List All </a> </li>
</ul>
</div>"
So, for ajax requests that you only want loaded once per page refresh/navigation, use server side timestamp.
$(function () {
$("#tabs").tabs({
beforeLoad: function (event, ui) {
if (ui.tab.data("loaded")) {
event.preventDefault();
return;
}
//ui.ajaxSettings.cache = false,
ui.panel.html('<img src="images/loader.gif" width="24" height="24" style="vertical-align:middle;"> Loading...'),
ui.jqXHR.success(function() {
ui.tab.data( "loaded", true );
}),
ui.jqXHR.error(function () {
ui.panel.html(
"Please Reload Page or Try Again Later.");
});
}
});
});
本文标签: javascriptCache JQuery UITabs Ajax loaded ContentStack Overflow
版权声明:本文标题:javascript - Cache JQuery UI-Tabs Ajax loaded Content? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132238a2422215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论