ajax return javascript to php
-
I have added some ajax that posts a javascript variable that I need to be able to use in a php function I have been able to see the output in the browser inspector as a preview but I cant get it to echo on screen. How do I get this to a php variable I can use in a function to determine users local time based on their timezone.
jQuery.ajax({ type: 'post', url: '/wp-admin/admin-ajax.php', data:{ 'action':'get_tz', 'tz':timezone.name() }, dataType: 'html', success:function(data){ }, error: function(errorThrown){ alert('error'); console.log(errorThrown); } });
wp_localize_script( 'daily_tee_tz', 'get-tz', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); add_action( 'wp_ajax_get_tz', 'get_tz_handler' ); add_action( 'wp_ajax_nopriv_get_tz', 'get_tz_handler' ); function get_tz_handler() { echo $_POST['tz']; die(); // Make sure you do this! }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘ajax return javascript to php’ is closed to new replies.