Answer the question
In order to leave comments, you need to log in
Why is there a 405 error when sending a POST request via axios to a php file?
I send a request via axios to a regular php file on the same domain for subsequent API access.
Everything works on the local server, but on the hosting, the
Error: Request failed with status code 405
js file error is returned when requested
const bodyFormData = new FormData();
bodyFormData.set('params', JSON.stringify({
data: this.data,
type: 'userdata'
}));
axios({
method: 'post',
url: '/ajax/info.php',
data: bodyFormData,
headers: {
"X-Requested-With": "XMLHttpRequest"
}
})
.then((response) => {
console.log(response);
})
.catch(er) => {
console.log(er);
})
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
if (empty($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] !== "XMLHttpRequest") {
exit();
}
//обработка
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question