So my script looks like this
function() {
$( "#tabs" ).tabs();
});
function Wczytaj(link, div_id, parametr1, parametr2, parametr3)
{
$.ajax(link, { data: { par1: parametr1, par2: parametr2, par3: parametr3 },
type: "post",
success: function(data) {
$('#'+div_id).fadeOut("medium", function(){
$(this).append(data);
$('#'+div_id).fadeIn("medium");
});
}
});
}
<div id="tabs">
<ul>
<li><a href="#id1" onClick="Wczytaj('trouble2.php','id1','null','null','null');">My id 1</a></li>
<li><a href="#id2" onClick="Wczytaj('trouble2.php?action=lista','id2','null','null','null');">My id 2</a></li>
<li><a href="#id3" onClick="Wczytaj('troubl2.php?action=old','id3','null','null','null');">My id3</a></li>
</ul>
<div id="id1"></div>
<div id="id2"></div>
<div id="id3"></div>
</div>
And it works without a problem, BUT I want to use also an URL address to load div content
for example, http://myurl.com/page.php#id2 should load page with selected tabs with id2 – it works, but div is empty because of onClick attribute. How to fix it?
I apologize for my english
You don’t need to use your own function to AJAX load into tabs, jQuery can do this for you. Just set the
hrefto the URL, and don’t add the<div>s.jQuery will make the tabs, and automatically load the page via AJAX. See the docs here: http://jqueryui.com/tabs/#ajax
It will also make the
<div>for you. In the example, they are namedui-tabs-X, whereXis the tab index. So,http://myurl.com/page.php#ui-tabs-2should load the page with your 2nd tab open.Check out jQuery’s demo here: http://jqueryui.com/resources/demos/tabs/ajax.html#ui-tabs-2
EDIT: If you want to run a function before or after the remote tabs are loaded, jQuery UI provides the
tabsbeforeloadandtabsloadevents.They can be bound when creating the tabs:
Or they can be bound afterwards: