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();
}
Related Posts:
- How to check if new posts have been published since page load?
- Can i check if user is doing any ajax request?
- How to use wp_localize_script in a WordPress page other than functions.php?
- Real time Duplicate title check
- Ajax template: how to handle head section
- Update WordPress Custom Field with AJAX on cached page
- Is the regular ajax request method safe or I should use admin-ajax.php?
- AJAX in WordPress, sending coords data to MySQL and show after into map
- Ajax form submit within a Post Metabox
- Returning a value from a PHP page
- Stumped – Ajax Response Returns 0
- Ajax $wpdb not returning table data
- How to run JS, PHP and etc. inside WP post?
- Trying to implement Ajax comments in WordPress, getting WP error
- Can’t search posts using WP_QUERY inside AJAX Function
- Woocommerce add to cart quantity buttons with AJAX
- Why is $_REQUEST an empty array in admin-ajax.php?
- AJAX request status 200 but no actual “response”
- Ajax – Call to undefined function get_option()
- Ajax load more posts with multiple tax query
- Ajax call not working
- WordPress Sending data to Ajax with select option
- How to get original custom taxonomy slug after the slug has been rewritten?
- Save Search System
- populate form fields in a loop with ajax
- dynamic dependent select dropdown
- Are nonces in WP REST API optional by default?
- How to pass Select value from Javascript to PHP to generate select option on change
- Plugins not working on AJAX requests
- Using Select HTML in Bootstrap Popovers
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- wp ajax return 0
- WordPress plugin: render only page content using ajax call
- AJAX button action in foreach
- HTML escaping data with ajax requests
- load ajax using admin-ajax.php
- Ajax button not working
- Function won’t run onclick using Ajax
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Simple AJAX notification when the new post is added to the database
- Is it possible to create new user from external form using REST API?
- Get related product based on subcategory selected from category id with ID 142
- When echo follow Ajax button inside Ajax pagination template not working?
- jQuery Ajax PHP function call returning [object Object]
- Retrieve Json data and create multiple pages with it
- WP_Query with AJAX returning empty array
- How to get post category list as select in front-end?
- PHP Warning: Missing argument 2
- Is there a hack for using is_page() within the function.php file?
- Submit form to db
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- Can not call .php files after switching to %postname%
- WordPress Conditional / Multiple Taxonomy Query
- custom add note meta box with add button in wordpress
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Disclaimer that will show every refresh of the page
- AJAX function running TWICE with WordPress admin-ajax.php
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- How to call my PHP function with AJAX ? wp_query
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- get_the_author_meta( ‘ID’ ) just return 1
- AJAX and custom pages
- custom mailchimp form using HTTP API
- $.ajax results in 403 forbidden
- WordPress is setting from header wrongly in wp_mail
- WordPress ajax filter returning all posts when it should be filtering by category
- ajaxurl usage for a custom function
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Prepared DB Query from _POST array
- Pass form attributes to another php template in wordpress
- Custom HTML form using PHP – help with ajax/username validation
- AJAX Filter WHILE Loop not working WordPress
- AJAX Returning Way Too Many Posts
- WordPress AJAX load post metadata in modal
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- wordpress ajax return 0
- Ajax call URL 404’ing when pushed to staging server
- Modify category archive page loop on functions.php
- Run insert if no entry otherwise run update with ajax
- Adding instant search to wordpress page
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Load php function with AJAX on modal window
- notify users when changed database
- WordPress Query -> Ajax Query
- How to use url and amin-ajax.php
- WP – Ajax call back data printed in the console.log
- How to Set Page Pagination Using Ajax JQuery – WordPress
- How to pass and validate nonce in custom REST routes
- Woocommerce – Include custom user meta in order ‘filter by registered customer’ Ajax search
- AJAX WP_Query’s order and orderby parameters not working
- How can I use AJAX in child theme template?
- Help with AJAX request
- Start a long running PHP process via JS/Ajax and monitor progress on admin page
- custom AJAX filtering logic and outputting results into an Elementor Loop Grid widget