I want to include 1 php file in “inc” folder in my WORDPRESS theme by ajax.
By the way i get the ID of “li a” when click per tab.
Please tell me what wrong in my code. I’m not good in javascript.
Thanks for help.
Here my JS code.
<script type="text/javascript">
jQuery(".tab_menu ul li a").click(function() {
jQuery("#result").html("<span class='loading'>Loading...</span>").fadeIn();
var $linkId = $(".tab_menu ul li a").attr("id");
$.ajax({
url: "<?php echo get_bloginfo('template_url').'/inc/';?>" +$linkId+ ".php",
type: "POST",
data: {tab: linkId},
success: function(msg){
jQuery(".loading").remove();
jQuery("<div>").html(msg).appendTo("div#result").hide().fadeIn("slow");
}
});
return false;
});
</script>
And here my tabs menu code:
<div class="tab_menu">
<ul>
<li><a id="">Tab 1</a></li>
<li><a id="tab_hinh_anh">Tab 2</a></li>
<li><a id="tab_binh_luan">Tab 3</a></li>
<li><a id="tab_ban_do">Tab 4</a></li>
</ul>
<div class="clear"></div>
</div><!--end tab-menu-->
My php file to include in “inc” folder and file name = linkId +.php (ex: inc/tab_ban_do.php)
When i Click per tab.. it fadeIn the Loading… text.. but not load php file.
And I view source: + linkId + not be change to ID of the tab. 🙁
Please try this:
It will work surely.