Jquery-ui tabs (ajax).... stop tab reloading url when tab is re-selected

Sir Lojik picture Sir Lojik · Feb 22, 2011 · Viewed 12.8k times · Source

I am using jquery ui tabs and im adding tabs dynamically using .tabs('add'...). The tabs load a url using ajax. The problem is that everytime i click on another tab then come back... the tab reloads the url. i want the url loaded once.... any ideas?

Answer

Cheekysoft picture Cheekysoft · Aug 29, 2013

Please note that the cache property of the tabs options was deprecated in jQueryUI 1.9 and removed in 1.10. See the jQueryUI 1.9 upgrade guide

The recommended way to handle this now, is to use the new beforeLoad event to prevent the XHR request from running.

$( "#tabs" ).tabs({
  beforeLoad: function( event, ui ) {
    if ( ui.tab.data( "loaded" ) ) {
      event.preventDefault();
      return;
    }

    ui.jqXHR.success(function() {
      ui.tab.data( "loaded", true );
    });
  }
});