I
I
inavo2020-06-13 19:07:21
Vue.js
inavo, 2020-06-13 19:07:21

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 file
<?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();
}

//обработка


No cms or framework, just a vue file and a php file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inavo, 2020-06-13
@inavo

The problem turned out to be stupidly simple. I took the cheapest hosting for tests, and it did not support php, so nothing was done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question