A
A
Alexander Tishchenko2021-10-29 00:23:15
AJAX
Alexander Tishchenko, 2021-10-29 00:23:15

Why is the server refusing to accept when sending data with a POST request (Axios)?

Hello.
There is such js-library Axios.
When you send data in a POST request to the server (PHP) like this:
" axios.post('site.com', 'session=1&text=blabla' )", then PHP accepts it in $_POST.
But when you post, in a different way: axios.post('site.com', { sessions:1, text: blabla }) . That answer is related to CORS, an error.
The question is why the server accepts the first option, and refuses the second option?
and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-10-29
@Rsa97

Of course, you didn't point out the error.
I assume that the problem is related to preflight requests. The server must correctly respond to OPTIONS requests with a 200 response code and all CORS headers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question