P
P
Pavel2019-04-19 11:47:22
PHP
Pavel, 2019-04-19 11:47:22

Why is $_POST empty (axios)?

Good afternoon. The problem is that when I send data via axios. In response, I get an empty $_POST.
request code

axios.post("/api.php?action=create", {myvalue:'строка', sub:'ahaha', value:22})
      .then(function(response){
        	console.log('Что-то произошло');
        if(response.data.error){
          app.errorMessage = response.data.message; 
          console.log('ошибка');
        } else{
          console.log('отлично');
        }
      });
      },

5cb98a5a5772c851837774.jpeg5cb989f8296f9368037565.jpeg5cb98ae2481c7134243194.jpeg5cb98a6ad8dc0288907484.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2019-04-19
@ppyl

Thank you all for your replies, issue resolved.
In order for $_POST not to be empty, you must first write in PHP:

$_POST = json_decode(file_get_contents('php://input'), true);
and then access the necessary attributes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question