• pczk

    (@podlasiaczek)


    Hello,

    I have a problem with tooltips after importing ajax. Tooltips not visible.

    custom.js

    
    (function($){
        'use strict';
        $(function (e) {
            $('.get_project').on( 'click', function(e) {
                e.preventDefault();
                var postid = $(this).attr('data-postid');
                console.log(postid);
    
                $.ajax({
                    type: "POST",
                    url: my_ajax_object.ajax_url,
                    data: {
                        action: 'my_load_ajax_content',
                        postid: postid,
                    }
                }).done(function (data) {
    				 
    				$('.TARGETDIV').html(data).trigger('post-load');
    
    				
    				
                });
            });
        });
    })(jQuery);

    functions.php

    
    function my_load_ajax_content () {
        $pid = intval($_POST['postid']);
        $the_query  = new WP_Query(array('p' => $pid));
    
        if ($the_query->have_posts() && $pid > 0) {
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                $data = '
                <div class="post-container">
                    <div id="project-content">
                        <h2 class="custom-h2">' . get_the_title() . '</h2>
                        <!-- <div class="entry-content">'. get_the_content() . '</div> -->
    					<div class="entry-content">' . do_shortcode(get_post_field('post_content', $pid)). '</div>
                    </div>
                </div>  
                ';
            }
        }
        else {
            $data = '<div id="postdata">'.__('Not found', THEME_NAME).'</div>';
        }
        wp_reset_postdata();
    
        echo '<div id="postdata">'. $data .'</div>';
        die();
    }
    
    add_action ( 'wp_ajax_nopriv_my_load_ajax_content', 'my_load_ajax_content' );
    add_action ( 'wp_ajax_my_load_ajax_content', 'my_load_ajax_content' );
    
    function my_enqueue() {
        wp_register_script( 'ajax-script', get_template_directory_uri() . '/js/custom.js', array('jquery') );
        wp_localize_script( 'ajax-script', 'my_ajax_object',
            array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
        );
    	
        wp_enqueue_script( 'ajax-script' );
    	
    	
    }
    
    add_action( 'wp_enqueue_scripts', 'my_enqueue' );
    
    

    Please help, Regards

  • The topic ‘Get data Ajax – tooltips problem’ is closed to new replies.