I would like to get template part with AJAX. This template part - more-images.php contain of source some wp php and html.

I read AJAX is build in WP. So I put code below to my theme files. My code:


function get_img()
    get_template_part('more', 'images');

add_action( 'wp_ajax_get_img', 'get_img' );
add_action( 'wp_ajax_nopriv_get_img', 'get_img' )

javascript file with other functions, loaded in the footer

            url: params.url,
            type: 'post',
             data: {  
                action: 'get_img',
success:  { $( 'main' ).append( data );         
     }, });

That code doesn't work.


You don't need buffer here.

get_template_part('more', 'images');
| improve this answer | |
  • Thank You. However the code isn't working. I receive unexpected string. When I remove line: success: { $( 'main' ).append( data ); it says params is not defined. – Dom.in Feb 9 '18 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.