views:

36

answers:

2

Hi

I am wondering if anyone knows how to solve this problem. I am using the jquery ui tabs and each tab I have is ajax enabled with caching disabled. So every time the tab loads it should load up all the content again.

It does this but what I don't like is first it displays the old version first while it is trying to load up the new content.

So say if I do this

Click on Tab A it loads up. I then click on Tab B and it loads up. I then click on Tab A again and I see the previous load up of the first time around. As the user I want to click on a button in Tab A so I do that but the thing is that it is trying to load up Tab A again(since it is no caching enabled). So when the user clicks the button nothing will happen and all of a sudden the tab will refresh itself since it has gotten all the new ajax request since it finished loading.

So is there a way when the user clicks Tab A for the second time they don't see the old version or anything till it's finished loading.

Thanks

Edit

 $('#tabs').tabs(
            {
                select: function (event, ui)
                {
                    $('#tabs .ui-tabs-hide').children().remove();
                }
            });
+1  A: 

you can take a look at the event select, that is fired if a tab gets clicked.

http://jqueryui.com/demos/tabs/#event-select

There you should be able to remove the old content while the new content gets loaded.

You could try something like this: (untested)

$("#your_tabs_box_id")
  .bind("tabsselect", function(event, ui){
    ui.panel.css('visibility','hidden');
  })
  .bind("tabsload", function(event,ui){
    ui.panel.css('visibility','visible');
  });
jigfox
what is this ui.panel.css stuff? You can see what I did it seems to to work but if I can get there built in classes I rather do that since I don't like using css selectors on plugins since they maybe just change the names one day.
chobo2
`ui` is the ui-element on which the event is triggered. `ui.panel` is the panel with the content of the tab. and `ui.panel.css()` is a standard jQuery function! More info on `ui`: http://jqueryui.com/demos/tabs/#Events, and more info on `.css()`': http://api.jquery.com/css/ . Everything standard, and nothing should be changed in future releases, only extended more functionality..
jigfox
A: 

A combination of the select event and emptying ui.panel will do it. From the documentation (tabs overview):

$('#example').bind('tabsselect', function(event, ui) {

    // Objects available in the function context:
    ui.tab     // anchor element of the selected (clicked) tab
    ui.panel   // element, that contains the selected/clicked tab contents
    ui.index   // zero-based index of the selected (clicked) tab

});

so:

$(document).ready(function(){
    var $tabs = $("#selector").tabs({ select: function(event, ui) {
                                          $(ui.panel).empty();
                                      }
                               });
});

or:

$('#selector').bind('tabsselect', function(event, ui) {
    $(ui.panel).empty();
});
karim79
That seems to work great. any difference to doing it as the tab is initialized versus binding? Also is empty equivalent to children().remove()?
chobo2
@chobo2 - as far as I know, they are the same. I think `empty()` is more suitable that `children().remove()` since it is more direct, it will simply set the innerHTML of the container to nothing. Also, `children().remove()` may not remove unwrapped text nodes from within the container.
karim79
How can I unbind tabselect. I don't need it on one of my tabs so I want to unbind it. But it does not seem to work.
chobo2