0

I am new to express framework, in my application I use axios to send HTTP requests to a php server. I am using following code to send POST requests to a php page with parameters 'username' and 'password' as described in the axios documentation. But my php server does not receive any POST parameters, because

echo($_POST['username']); 

doesn't return anything. Can anyone tell me what I am doing wrong here & instruct me to correct this without changing the php files? following is the code which I used to send HTTP POST requests

axios.post('http://localhost/test/login.php', { username: 'test', password: 'user@test' }) .then(function (response) { console.log(response.data); }) .catch(function (error) { console.log(error); });

1

1 Answer 1

2

See the documentation for axios:

By default, axios serializes JavaScript objects to JSON.

PHP doesn't automatically parse JSON formatted requests.

You'll need to either send data in a format that PHP will decode into $_POST as described in the documentation linked above, or write your PHP so it can handle a JSON encoded request (as described in this answer).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.