I don’t know if there is really a right answer to this question, and I don’t know what you find cumbersome about wp_localize_script
, but you should be able to do it either way.
The difference is that with wp_localize_script
the data is printed to the source of the page, which you wouldn’t want if the data were sensitive, and wp_localize_script
should represent a wee bit less load on the server as it doesn’t require a separate connection as AJAX does.
I’d lean towards wp_localize_script
unless there are compelling reasons to do something else.
Related Posts:
- Is there a JavaScript API? How to access public and private data in JS?
- jQuery Autocomplete not working with wp_localize_script
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Can’t seem to get wp_localize_script to work
- Cannot update my options using wp_ajax
- How to localize inline script called with ajax
- Nonces, AJAX, script variables & security in WordPress
- Ajaxing in functions.php
- How to make get_theme_mod work with AJAX in the customizer preview
- how to send Ajax request in wordpress backend
- Populate a Map at The Same Time as showing Posts via AJAX
- wp_localize_script not working on ajax response
- How to make tabulator ajax call in wordpress?
- Admin-Ajax Error
- Why is wp_localize_script returning false?
- Ajax call with javascript in post content (not enqueued)
- How to add ajax url to js using wp_add_inline_script()?
- update_option is not saving an array, but saving the string ‘Array’
- Front end theme options ajax returns 0
- WordPress Ajax Filter
- Is there a better way to access transients using javascript
- update_option in WordPress AJAX
- How to perform a frontend HTTP call with AJAX when plugin save the new settings?
- Why the wp_localize_script() does not work correct in my case? ( /wp-admin/admin-ajax.php 400 (Bad Request) )
- Get localize of a loaded javascript
- WordPress Select Option Load Custom Fields
- How to Object.freeze wp_localize_script
- Ajax is not defined
- Ajax WordPress pass post URLs
- AJAX save options inside class
- AJAX call in backend results in empty update_option
- Using AJAX for dynamic settings pages
- wp_localize_script not create variable in head section
- using Ajax: call to undefined function get_option
- register_setting and AJAX?
- WordPress wp_localize_script nonce and ajax URL
- Uncaught ReferenceError: custom_ajax is not defined
- Object name undefined using localize script
- PHP “php://input” vs $_POST
- Google Maps API throws “Uncaught ReferenceError: google is not defined” only when using AJAX
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- How to solve the error “SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE
- Show spinner GIF during an $http request in AngularJS?
- Refresh HTML Page in Browser Automatically on Timer – Every 15 Min
- JavaScript implementation of Gzip
- jQuery: Performing synchronous AJAX requests
- ASP.NET MVC controller actions that return JSON or partial html
- jQuery’s .on() method combined with the submit event
- Ajax takes 10x as long as it should/could
- How to check if I am in admin-ajax.php?
- Best way to end WordPress ajax request and why?
- How to load wp_editor() through AJAX/jQuery
- get_option() vs get_theme_mod(): Why is one slower?
- How to cache json with wp-super cache
- Load minimum WordPress environment
- Why use wp_send_json() over echo json_encode()?
- Why use admin-ajax.php and how does it work?
- How to get a unique nonce for each Ajax request?
- Open a Thickbox with content trough AJAX
- Initialize TinyMCE editor / visual editor after AJAX insert
- Why not register shortcodes if is_admin dashboard?
- Using jQuery to delete data stored in wp_options
- WordPress AJAX with Axios
- Why is die() used at the end of function that handles an Ajax request?
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Making my AJAX powered WordPress Crawlable
- Get Previous & Next posts by Post ID
- Passing boolean values with wp_localize_script
- failed to load wp-admin/admin-ajax.php
- Using Backbone with the WordPress AJAX API
- Using Ajax with a Class file
- Ajax in a settings page (update_option is undefined)
- How to pass data parameter to ajax action function handler
- WordPress Ajax Data Security
- Displaying PHP Errors from admin-ajax.php
- How To Add New Option Types To Option Tree?
- Best practices for a Style/CSS based theme options page?
- wp_set_auth_cookie() doesn’t work in Ajax call
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- WP-AJAX vs WP REST API: What to use for requests to the website from outside?
- Ajax and autocomplete
- How to add to cart via AJAX Woocommerce [closed]
- Nonces and Cache
- SSL breaks customizer: page isn’t returned from ajax
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- How to HTML5 FormData Ajax
- admin-ajax.php vs Custom Page Template for Ajax Requests
- How to override WP_DEBUG for Ajax responses?
- Stop admin-ajax?
- redirect out of wp-admin, without losing admin-ajax.php
- Call to undefined function add_action()
- Is it safe to assume that a nonce may be validated more than once?
- Including WordPress in RESTful API
- Multiple ajax nonce requests
- Get posts with ajax
- admin-ajax.php doesn’t work when using POST data and Axios
- How to call a PHP function with Ajax when the user clicks a button