Your code looks correct.
alert(wp_ajax.nonce);
should display the nonce.
You can also verify the existence of the wp_ajax
object via console.log(wp_ajax)
in your browser’s Javascript console.
wp_localize_script
adds the object(s) to the footer (a call to wp_footer()
should be present in the theme’s footer.php file).
It’ll look like so:
<script type="text/javascript">
/* <![CDATA[ */
var wp_ajax = {"url":"http://example.com","nonce":"123XYZ"};
/* ]]> */
</script>
Related Posts:
- Is there a JavaScript API? How to access public and private data in JS?
- wp_localize_script not working on ajax response
- Get localize of a loaded javascript
- Ajax is not defined
- wp_localize_script with boolean and init
- jQuery Autocomplete not working with wp_localize_script
- Can’t seem to get wp_localize_script to work
- How to localize inline script called with ajax
- Nonces, AJAX, script variables & security in WordPress
- Ajaxing in functions.php
- How to declare a JS variable in an AJAX call
- Enqueue script dinamically
- Enqueue script in header
- how to send Ajax request in wordpress backend
- Populate a Map at The Same Time as showing Posts via AJAX
- WordPress Ajax problem with undefined url
- How to make tabulator ajax call in wordpress?
- Admin-Ajax Error
- WordPress Ajaxify Problem with Scroll-to [closed]
- Enqueue script in plugin is not working
- wp_enqueue_script() doesn’t work with AJAX
- 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()?
- How to include php-generated javascript?
- 403 error When i send ajax request on WordPress website
- WordPress Ajax Filter
- Is there a better way to access transients using javascript
- How to load dynamic option with ajax
- Why the wp_localize_script() does not work correct in my case? ( /wp-admin/admin-ajax.php 400 (Bad Request) )
- edit user input data contact form 7
- How to Object.freeze wp_localize_script
- I am getting Admin-ajax.php 400 Error
- Ajax WordPress pass post URLs
- Ajax Response Error | just getting error as the response
- why is my main.js not loading?
- Enqueue dynamically generated javascript
- wp_enqueue_media problem
- Ajax navigation and scripts loaded only on certain pages
- AJAX admin Internal 500 error Failed to Upload
- Using WP Ajax and jQuery to process multiple forms on the same page?
- WordPress wp_localize_script nonce and ajax URL
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- How to check if I am in admin-ajax.php?
- Is it possible to use wp_localize_script to create global JS variables without a specific script handle?
- Execute one AJAX request after another AJAX request finished
- Ajax and autocomplete
- Saving (Updating) Post / Page Edits With AJAX
- Is there a hook that fires before an ajax call?
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- Confused on AJAX submit form through page template
- Ajax call in wordpress not working for subscriber user in front site
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Why does WordPress Heartbeat login not refresh the nonces?
- wp_localize_script escaping my url – fix or alternative
- Insert wp_editor on front-end with AJAX?
- Buddypress: Load Ajax Without Template Pack [closed]
- Woocommerce Ajax Add cart not working
- I have to post data by AJAX in wordpress to another Website
- Placement of add_action() for ajax callback?
- Identical wp_rest nonce returned from rest_api
- wp_handle_upload returns empty error array
- Interim-Login form on frontend
- Save value from Javascript object to WP user
- add Additional class to woocommerce cart-contents link
- Ajax insert or update data
- Check ajax triggered from front-end or from dashboard
- Add Ajax to rating button
- Delete ACF repeater field row on Front End
- No errors in the console but Ajax call doesn’t seem to be working
- Preprocess submitted data
- Update status, meta while inside a post using AJAX button
- How to disable drag-and-drop upload function in Media Library?
- Can’t retrieve any content from Ajax-loaded page
- admin-ajax.php not loading anymore
- How do you use do_shortcode via AJAX call?
- Auto-suggest to display meta-data, but not to include it upon click
- Loading pages via Ajax and displaying titles
- change wordpress pagination url after doing the request
- How to send automatic response after form submission without plugin
- Refresh Gutenberg with JS for it show updated post
- How to return a record from a custom table by sending an AJAX request
- React to AJAX adding to the page
- gform_after_submission does not work on ajax enabled form
- Ajax call not working anymore
- Ajax global variable is not getting saved (returns null)
- Calendar month navigation in Ajax only working once
- 403 error for ajax POST request
- Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
- How modify comments metabox on post edit screen in WordPress?
- How to get, in WP page’s script, a wp enqueued script (in Functions.php)?
- my ajax action doesn’t get hit
- Get Page Type (Category/Tag) Using AJAX
- Data from ajax not updating post meta
- Remove dashboard access but allow ajax file upload
- wordpress ajax bad request 400