It’s working, I traced it by digging through admin-ajax.php to see what was responding with 401/400. My fix was basically making the action
parameter the last thing appended to the formData
formData.append("enquiry", form);
formData.append("action", "enquiry");
I don’t normally use formData to post things, .serialize()
has always been enough for me over the years. As I spend most of my time doing C# and PHP using JSON without the WordPress overhead I just assumed the same things not taking into consideration you need to hook into WordPress to make everything behave.
But I do vaguely recall something (non-WordPress) from a fair while back about the order of items added to formData, Or I might just have dreamt it.
@Tom: I’d still be interested to hear more about the REST solution.
Related Posts:
- Do I require the use of nonce?
- simple wordpress ajax plugin not working when not logged in
- Problem with WordPress Ajax form
- How to set a custom path, for ajax image upload folder in admin?
- admin-ajax.php responding with 0
- Page Reloads Before AJAX Request Finishes
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- How to test nonce with AJAX – Plugin development
- Create onClick Event to Re-load a Widget
- WordPress ajax doesn’t display object method on jQuery .change() function
- adjust section according to country?
- How to send Ajax request from my plugin in admin dashboard?
- AJAX success response is not working but it’s saving my changes
- how to update and display an option without reloading the page
- Using data sent via AJAX in multiple functions on a WP plugin
- Problem with AJAX in wordpress plugin
- Execute Jquery when a specific page in my plugin is loading
- PHP: How to access db the right way in plugin?
- calling admin-ajax.php from admin-ajax.php
- Submit form to db
- How to use wp_send_json() and output the value with ajax?
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Is it possible to access admin-ajax.php using PHP?
- Settings API form – submit with AJAX
- Post form – AJAX won’t upload featured image – Plugin development
- How can I get my WordPress plugin to receive data and relay it in an ajax/php request to a remote server that requires authentication?
- Submit remote form to wordpress REST API and save data to custom post type
- custom mailchimp form using HTTP API
- 400 bad request admin-ajax file upload
- Input field duplicates on form submit by jQuery
- Ajax in a class instantiated via shortcode
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Cookie not created in AJAX request
- How to pass and validate nonce in custom REST routes
- getJSON response to PHP
- ajax problems on loading page [closed]
- Should I use spl_autoload_register() in my plugin?
- How can I save a multiple select array with the settings API for a plug-in options page?
- Using register_activation_hook in classes
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Where to include php files in wordpress and how to refer to them later [closed]
- Passing JSON data from WP Query into AJAX causing NULL errors
- Validate a users email address when using gmail to register
- Making Quote Plugin more efficient
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- How to make custom total price reactive in navigation
- Instantiate class to be available to all plugin functions
- WooCommerce get_price returning wrong price when used via ajax
- WP nonce invalid
- get current custom post ID by WP_Query method
- Creating a Multi-Level Associative Object Using AJAX
- Reprinting tags with all attributes
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Posting and image insertion problems after EasyApache4 and PHP 7 upgrade
- How to add a do_action on refreshing of WP customizer?
- Adding function to Genesis genesis_header [closed]
- How to obtain the current website URL in my theme?
- Plugin Generate Unexpected output during activation
- Undefined method class::construct() when creating a plugin
- how to Update 15k products on plugin activation with meta_option
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Errors being created by admin-ajax.php
- Adding Additional Variables on Menus Page
- Can’t pass the variable from a select to PHP query
- Accessing an API with jQuery and AJAX
- Ajaxurl suddenly not defined
- How to correctly escape an echo
- Payment field disappears on custom Paypal plugin
- How to Remove Theme Style CSS inside Custom Plugin?
- Store ajax data in PHP variable
- Creating plugin with front-end pages
- How to Send Pingbacks for all Posts in WordPress?
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- get Woocommerce product format json for WP_Query
- wp_ajax_ 400 Bad Request
- Why the responseText containing those two arrow signs at the beginning
- WordPress Ajax filter: Create two loops for different output styles?
- The plugin generated 225 characters of unexpected output during activation
- Following/Followers Users list Using Ajax Pagination inside Author Profile
- How to call a function from functions.php with ajax?
- Problem with ajax request and directory structure after site migration
- Send data from plugin to external database
- ajax form with multiple submit buttons and values
- See output of a sql query while plugin installation in wordpress
- ajax form function error
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- wp_enqueue_scripts with JS script as a string
- base64_encode conflict with convert_smilies in wordpress
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- How to use url and amin-ajax.php
- WP – Ajax call back data printed in the console.log
- Implement OAuth2 in custom plugin
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to lock users account until approvation
- Variable ++ in query loop
- AJAX WP_Query’s order and orderby parameters not working
- How can I use AJAX in child theme template?