Jquery Tabs and ajax
Jquery Tabs and ajax
Hi,
im trying to add some tabs (loading pages with ajax) to make it easier to navigate through my pages that mostly will contain datatables that are also using ajax to get their data.
i tried this simplest solution, but only the first tab would load the table and also the page was loaded with wrong margins, besides other things, it simply didnt work..
is there any way to do this? i have several pages and i use cookies to validate user input so it would be impossible to put everything on just one page.
thanks!!!
[code]
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Error" );
}
}
});
});
Table1
Table2
Table3
Table4
[/code]
im trying to add some tabs (loading pages with ajax) to make it easier to navigate through my pages that mostly will contain datatables that are also using ajax to get their data.
i tried this simplest solution, but only the first tab would load the table and also the page was loaded with wrong margins, besides other things, it simply didnt work..
is there any way to do this? i have several pages and i use cookies to validate user input so it would be impossible to put everything on just one page.
thanks!!!
[code]
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Error" );
}
}
});
});
Table1
Table2
Table3
Table4
[/code]
This discussion has been closed.
Replies
*Personally*, I would consider re-engineering the approach rather than trying to figure out how to then execute the script on retrieval.
Have your 4 tabbed areas ready with empty tables. If there's a bunch of stuff on your page1, page2 etc. pages, you could always fetch them with your tab solution or via PHP includes. But the key is that you don't bother including the scripts on those includes, and the tables are just empty.
The scripts live on the parent page, and you write a new function that is triggered when a tab is clicked. On tab click, switch to the new tab and run dataTable() on the corresponding table. You could include functionality that will detect which tab is active (if the tabs are opened based on cookies, for example), or fire .click() on the tab you need to. There are a bunch of different ways you could work out the actual logic.
That's just the way I would approach it.
---
Whether you pursue something along the lines of what you're already doing, or whether you decide to give my idea a try, remember that you cannot have the same ID for each of your 4 tables.