Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax request return ERR_BAD_REQUEST Request failed width status code 400 #4648

Closed
valentin6work opened this issue Apr 27, 2022 · 7 comments
Closed

Comments

@valentin6work
Copy link

Describe the bug

I have error ERR_BAD_REQUEST Request failed width status code 400 after send ajax post request

To Reproduce

WordPress 5.9.3 send any ajax request to /wp-admin/admin-ajax.php

let form_data = new FormData;
form_data.append('action', 'any_action');
form_data.append('etc..','any value');

axios.post('https://myhost.com/wp-admin/admin-ajax.php', form_data)
.then(function (response)
{
	//--- 
})
.catch(function (error) {
	console.log(error);
});

PHP code in function.php

$action='any_action';
add_action("wp_ajax_nopriv_$action", "$action");
add_action("wp_ajax_$action","$action" );
function any_action)
{
	echo json_encode([
        'post'=>$_POST,
    ]);
    wp_die();
}

Expected behavior

Return result json. Its worked until April 26th!

Environment

  • Axios Version [0.27.2]
  • WordPress 5.9.3

Additional context/Screenshots

https://prnt.sc/XI2ozoTn9Hgf

@jasonsaayman
Copy link
Member

Please check out the docs over here, we have changed the way form data works.

@satanshiro
Copy link

Please check out the docs over here, we have changed the way form data works.

fyi the link is for the minified dist instead of docs

@jasonsaayman
Copy link
Member

My bad here

@apasov
Copy link

apasov commented Apr 27, 2022

I got this 400 error with v0.27.1
After upgrading to v0.27.2 it disappeared.
Looks like it was fixed in #4640

@DigitalBrainJS
Copy link
Collaborator

DigitalBrainJS commented Apr 27, 2022

Actually, we did not change anything in working with FormData - we just added alternative shortcut methods and payload serialization to a FormData object when you set the content-type header to multipart/form-data for plain object payload. This is just another shorter way to submit a form without manually creating a FormData object. The old behavior should not be affected, you can still pass the FormData object manually. FormData submits fails were only due to two regression bugs in versions 0.25.0 and 0.27.0.

@anniverskehinde
Copy link

🙄**I am Lerner here **

@philBrown
Copy link

regression bugs in versions 0.25.0 and 0.27.0

... and 0.27.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants