Support » Developing with WordPress » Live notification Ajax not work

  • Hi,

    I need to create ajax notification popup when one query return true. My code from plugin is below:

     }, 5000);
     function load_last_notification()
       dataType: "JSON",
           var respose = JSON.parse(data);

    In my page exist:
    <div class="request-notification"></div>


    global $wpdb;
    $current_user = get_current_user_id();
    $output = '';
    $thread_id_request = $wpdb->get_var( $wpdb->prepare( "
            SELECT <code>thread_id</code>
            FROM <code>{$wpdb->base_prefix}table</code> 
            WHERE <code>user_id</code> = %d
            AND <code>accept_status</code> = 0 
        ", $current_user ) );
        $output .= '<div>Test from the other side</div>';

    What is wrong? or How I can create live notification for user when query return true?

    Thanks for support and time!

    • This topic was modified 4 months, 3 weeks ago by  pavelmititel.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    It’s not clear how you are loading the jQuery library. The local WP version of jQuery does not allow for $ shortcuts, you must spell out jQuery or implement a noConflict wrapper.

    In order to get current WP user data, your Ajax request must go through /wp-admin/admin-ajax.php. Thus your request must include an “action” value which is used to construct an action hook tag. Your Ajax handler would thus be in the form of an action hook callback function.

    That’s right, Ajax in WP has a few quirks. For more specifics on using Ajax in WP, check out the Plugin Handbook:

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.