I have a quick question. Did anyone managed to use Axios inside WordPress to do AJAX requests (wp_ajax with action – calling a function) not REST API and how did you do it?

It seems that Axios is sending a JSON and whenever I try the request I get a 0. However, using jQuery AJAX it works fine.

2 s
2

you can use FormData

an example:

let form_data = new FormData;
form_data.append('action', 'myAction');
form_data.append('first_name', 'my first name');
form_data.append('phone', 'my phone');

axios.post(myVars.ajax_url, form_data).then(function(response){
console.log(response.data);
})

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *