Try using get_template_part()
function. use ob_end_clean() to Clean the output buffer and turn off output buffering. I have use html()
to append data jQuery('#ajax').html(response.content);
. I have tested and working fine for me.
jquery :
jQuery("#ajaxbtn").click(function () {
jQuery.ajax({
type : 'post',
dataType : 'json',
url : myajax.ajax_url,
data : {action: 'tablo'},
success: function(response) {
jQuery('#ajax').html(response.content);
}
});
});
ajax function :
add_action('wp_ajax_tablo', 'tablo');
add_action('wp_ajax_nopriv_tablo', 'tablo');
function tablo() {
// Grab php file output from server
ob_start();
get_template_part( 'ajax' );
$result = ob_get_contents();
ob_end_clean();
$return = array('content' => $result);
wp_send_json($return);
wp_die();
}