refresh php function with jquery
-
hey everybody.
i want to refresh a php function every 30 sec and my code is :
—
// php function<?php function circlemessageshow() { global $wpdb; $mymessage = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_id = 142"); foreach($mymessage as $page){ $circlemessageshowbox = $page->option_value; return $circlemessageshowbox; } }; ?>
save in refresh-circlemessage.php
// my js code
function circlemessage() { // I test every code But not Working // tested one by one // return circlemessageshow() function => output : show content but not refresh data every 2sec return document.getElementById('circlemessageshow-refresh').innerHTML = refresh_object.php_function; // when load refresh-circlemessage.php and load circlemessageshow() function in this file => output : Call to a member function get_results() on null $("#circlemessageshow-refresh").load(refresh_object.php_url); } $(document).ready(function() { setInterval(circlemessage,2000); });
enqueue script file with localize
function add_refreshjquery() { wp_register_script( 'refresh-js', get_template_directory_uri(). '/js/refresh.js', array('jquery'), '1.0.0', true ); wp_localize_script( 'refresh-js','refresh_object',array( 'php_url' => get_template_directory_uri(). '/template-parts/refresh-circlemessage.php', 'php_function' => circlemessageshow(), 'php_url_config' => get_site_url(). '/wp-config.php', 'php_url_load' => get_site_url(). '/wp-load.php' )); wp_enqueue_script('refresh-js'); } add_action('wp_enqueue_scripts', 'add_refreshjquery');
and html tag for show message
<div class='circlemessage-esteam-modalbox-body' id='circlemessageshow-refresh-content'> <div id='circlemessageshow-refresh'></div> </div>
anybody can help me to resolve it ( if another way can work , plz say it)
ty for every body
Good Luck
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘refresh php function with jquery’ is closed to new replies.