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
- Why use admin-ajax.php and how does it work?
- Using Backbone with the WordPress AJAX API
- WordPress Ajax Data Security
- How To Add New Option Types To Option Tree?
- How do I hook an Ajax request into a PHP callback?
- Submenu pages delete settings from options array when saved
- get_template_part execute with ajax
- How to add WordPress nonces to ajax request
- How declare Ajax functions ussing SHORTINIT
- Load custom formatted comment with AJAX: reply link isn’t rendered?
- Need help understanding/coding with Settings API
- Is there a way to optimize function that is used for returning data in an ajax-call?
- WP REST API route request explain
- Ajax returning correct data BUT at wrong place
- admin-ajax.php mixed content
- WooCommerce: Translation lost on AJAX call in Checkout page [closed]
- Async Loading of Custom Posts
- Can’t save options
- Does wp_localize_script call a Javascript Function or Simply Pass PHP Parameters to It
- Call javascript function when category was added via ajax
- How to add WP API and JS featured image attachment
- Using AJAX with Forms
- Can’t publish post using ajax
- Ajax in plugin settings page returns 400 Bad Request
- How to localize admin.php only once
- Customizer AJAX using buttons
- WordPress Ajaxify Problem with Scroll-to [closed]
- Stop ajax listener from sending empty parameter to function
- Can’t trigger an AJAX function with a submit button in the dashboard
- AJAX Call is Only Returning 100 Results from Query
- How to make custom button link on the WordPress Admin Bar run by AJAX
- Ways to load admin-ajax faster without initializing all plugins?
- is_single() conditional check inside ajax php function
- WordPress action – Pass arguments into action in an AJAX call?
- Output multi-steps form results in same page
- Full Front End, AJAX comment system and comment reply script
- Ajax not working for certain user roles
- Tabbed feeds with ajax vs. without on homepage [closed]
- Get title and featured image using Ajax
- My function containing a mysql query launched by ajax is not working in wordpress. What am I missing?
- Not getting ajax success response on insert/update row to database
- Wp admin ajax load more
- wordpress ajax search posts
- Can’t get next post info with ajax
- How to inject data content from external json into a modal, using UIkit?
- Ajax by worpdress affects called jquery inside template file
- AJAX form not working, still reloads on submit
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Cannot access class properties from ajax call in wpordrpess
- why is my main.js not loading?
- Having a self updating list
- Enqueue dynamically generated javascript
- First time doing Ajax with WP, how to do it?
- Using Customizer value in an external PHP file inside a theme
- Unexpected WordPress search results
- WordPress Get Header and Footer using in Admin Area
- ajax page template
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- Why does my Ajax Get request give a 400 bad request?
- Translating wordpress foreach to ajax
- AJAX loading with custom parameters
- Placing ajax actions in different class
- randomly get 400 error while user is logged in wp_ajax