Answer the question
In order to leave comments, you need to log in
Why is nothing returned when sending via axios?
I send a simple request to a php file, but an empty request is returned.
axios.post('/ajax/data.php', {test: 'test'})
.then((response) => {
let data = response['data'];
console.log(data);
})
.catch((error) => {
console.log('error', error);
});
echo 'post= ' . json_encode($_POST);
Answer the question
In order to leave comments, you need to log in
In general, understood.
Rewrote it like this:
const bodyFormData = new FormData();
bodyFormData.set('data', JSON.stringify({
url: this.url,
test: 'test'
}));
axios({
method: 'post',
url: '/ajax/data.php',
data: bodyFormData,
})
axios.post(
'/ajax/data.php',
'data=' + JSON.stringify({
url: this.url,
test: 'test'
})
)
$data = json_decode( html_entity_decode( stripslashes ($_POST['data']) ) );
echo json_encode($data);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question