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
- Uncaught ReferenceError: custom_ajax is not defined
- Object name undefined using localize script
- 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
- contact form 7 form not working in admin panel
- 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
- ajaxurl not defined on front end
- 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?
- Best way to end WordPress ajax request and why?
- How to load wp_editor() through AJAX/jQuery
- 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?
- 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
- 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
- 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