I want to dynamically call different template in the tab. I am stuck in this part, if someone can help me it I will be very great full. I did the calling of a single template but dynamically calling is being hard to me as I am new in ajax.
Thanks
<ul class="nav nav-tabs" id="ajax-tab">
<li class="sectionA"><a href="#sectionA" data-type="test">Section A</a></li>
<li><a href="#sectionB" class="section-b" data-type="test2">Section B</a></li>
</ul>
<div class="tab-content">
<div id="sectionA" class="tab-pane fade in active">
</div>
<div id="sectionB" class="tab-pane fade">
</div>
</div>
$('.sectionA a').click(function () {
var clickedId = $(this).attr('href'),
$this = $(clickedId);
$.ajax({
type: "POST",
url: 'http://acethehimalaya.dev/wp-admin/admin-ajax.php',
data: {
action: 'my_ajax_action',
post_id: <?php echo $postid; ?>
},
cache: true,
beforeSend: function () {
$this.empty();
$this.addClass('loading');
},
complete: function () {
$this.removeClass('loading');
},
success: function (data) {
$this.append(data);
},
error: function (MLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
function my_ajax_action(){
if ($test == '#sectionA') {
include(locate_template('test2.php'));
}else{
//call another template }die();}
1 comment
Comments are closed.