Localized Script Data updates only for logged users
-
Hello,
I’m running into a caching problem with an ajax function.I have a localized script to wich I pass some dynamic data. This data changes as non-logged users perform actions (Data are user metas), but the data passed to the localized script are not updated.
More specifically, the script is registered and localized by a callback php function that is called by ajax, something like this:
add_action( 'wp_enqueue_scripts', 'my_callback_function' ); function my_callback_function() { wp_register_script( 'my-script', get_stylesheet_directory_uri() . '/js/wp-myscript.js', array('jquery') ); $user_data = get_my_user_data(); wp_localize_script( 'my-script', 'js_data', $user_data ); wp_enqueue_script( 'my-script' ); }
Then in my wp-myscript.js I just try a simple
console.log(favorites_data);
But data are update only if user is logged in, otherwise they will remain the same of the first page load.
Any hint would be much appreciated.
- The topic ‘Localized Script Data updates only for logged users’ is closed to new replies.