The problem is that, you have added extra white space before wp_ajax
action. remove space from actions ' wp_ajax_my_action'
and ' wp_ajax_nopriv_my_action'
. because of extra space before ajax request, showing the 400 bad request error.
You should use :
add_action('wp_ajax_my_action', 'my_action');
add_action('wp_ajax_nopriv_my_action', 'my_action');
Related Posts:
- 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
- ajaxurl not defined on front end
- Check for featured image in WP_Query
- add_filter and remove_filter added before and after wp_query
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- WP_LOCALIZE_SCRIPT doesn’t work
- Cannot search post by taxonomy
- WP AJAX is not working, always returns 0
- Can I individually style items in the backend widget list?
- WP_Query returns no results
- Finding posts containing matching array elements in a meta field usign WP_Query
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Slow WP_query due to nested wp_query. Need Suggestions
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Password field is empty when using wp_signon();
- template_redirect or admin-ajax.php?
- Update Data parameter of a wp_localize_script() call
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Data not insert and update through ajax and jQuery in admin page?
- AJAX button with success callback. (Titan Framework)
- Best practice for plugin: always detect admin-ajax call?
- Adjust query on single
- Get cat parameter from admin-ajax
- WP_Query order posts by category
- Rate limiting ajax requests in WordPress
- Post Pagination does not working on WP-Query
- Can’t get query string in ajax call
- Ajax functions – no access to wp-admin.php only online
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- Loading jQuery library from WordPress admin
- Return custom product in ajax call loop
- How to include jQuery and JavaScript files correctly?
- How can I run AJAX on a button click event?
- Empty POST data on server on AJAX request using Angular $http
- jQuery in header or footer
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- wp_localize_script $handle
- Escaping built-in WP function return strings
- WP Cron doesn’t save or in post body
- Check if I am in the Admin Panel (wp-admin)?
- Using Ajax call in jQuery doesn’t work in widget
- Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
- Metabox Not Showing on Custom Post Type But On Pages and Post
- How to redirect to action on custom page within admin section
- Ajax in WordPress – path issue
- How to determine if the current file is loaded in a plugin or in a theme?
- Filter, or any way to dynamically change theme screenshot image?
- Should action callbacks start with a verb?
- Is It Always a Best Practice to Decouple the Frontend from the Admin Area When Developing a WordPress Application?
- Issue plugin commands in admin settings page
- Beginner advice
- How to render a time-of-day string like ’16:42′ with a site’s chosen time format?
- Are block templates incompatible with serialize_blocks?
- Programmatically modify an admin page UI of a WordPress site from my WordPress plugin
- Global State During an Admin Post
- Woocommerce checkout update totals with datepicker
- Including the necessary functions for a custom ajax registration form
- Render content after post title in wp-admin
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Form doesnt save to database
- Notice: Trying to get property ‘term_id’ of non-object
- Is it possible to restrict all admin pages except theme customisation and storefront using plugin?
- Selectively update themes in WordPress multisite
- How I can use order by of the custom post title?
- How do I link to a php file in my plugin directory?
- How to create custom settings page for custom plugin
- Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
- Ajax is not working in a loop
- unable to wp_enqueue_script(‘suggest’);
- Drawing the line between theme & plugin on large scale bespoke projects
- Apply styles to blockquote element with the WYSIWYG editor
- How to add plugin options in wp editor page
- Gutenberg blocks error: Each child in a list should have a unique “key” prop
- About a programming language starts with [closed]
- Create fixed static pages
- Workflow for new importer plugin – your advices?
- Get Posts by IDs (optionally)
- How do I duplicate a single post, with all its properties, and save it as a different post?
- Why my theme’s css not working on another site
- WordPress AJAX Request returns 400
- Ajax action has 200 status but response of No response data available for this request
- Google Web Core Vitals – management, how to in wordpress and advice
- How to add quick edit on the list of users to edit custom fields?
- Impossible to declare box-shadow with wp.customize?
- Override category archive page title (not the head title)
- Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin
- How to handle ajax Request in a complex-structured plugin?
- Stop unauthorised file access
- PHP includes with AJAX actions
- Dynamic sidebar areas not working on the Theme Customizer
- Plugin dev: How to multiply instances of a plugin in the same metabox?
- Merge Codes using redux framework
- Issue on Getting Images URL of the Post Gallery
- Best practice: What belongs in theme and what in plugin for large eCommerce website
- variable created in page.php is null inside of header.php
- Page reload occurs before request finishes
- append code after the_content not working
- Problem with Poedit [closed]
- Is Explicit Versioning a better alternative to Semantic Versioning for wordpress?