decree
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Developing with WordPress
In reply to: refresh php function with jqueryhey guys
i ask question a few days ago about refresh php function with jquery and my dear friend joy said : use wordpress ajax interface
i solved my problem and share it :
::::::::::::: my js code :::::::::::::jQuery(document).ready(function($) { var data = { 'action': 'refresh_message' // We pass php values differently! }; // We can also pass the url value separately from ajaxurl for front end AJAX implementations function refreshmessage() { jQuery.post(refresh_object.php_ajax, data, function(response) { $("#circlemessageshow-refresh").html(response); }); } setInterval(refreshmessage,000); }); <a href="https://codex.wordpress.org/AJAX_in_Plugins" rel="noopener" target="_blank">source</a>::::::::::::: my php code :::::::::::::
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_ajax' => admin_url( 'admin-ajax.php' ), )); wp_enqueue_script('refresh-js'); } add_action('wp_enqueue_scripts', 'add_refreshjquery'); add_action( 'wp_ajax_refresh_message', 'my_action' ); function my_action() { global $wpdb; $mymessage = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_id = 142"); foreach($mymessage as $page){ $circlemessageshowbox = $page->option_value; echo $circlemessageshowbox; } wp_die(); }- This reply was modified 7 years ago by decree.
Forum: Developing with WordPress
In reply to: refresh php function with jquerydear joy
thank you for answer and for showing way to resolve this problem
Viewing 2 replies - 1 through 2 (of 2 total)