var params = { username: 'admin', password: '123456' } axios.post('test.php', params).then(res => console.log(res.data))
php code as follows
// pass a json object can file_get_contents ( "php: // input" ) acquired json string, then converted to obtain object attribute $ Data = file_get_contents ( "PHP: // INPUT");
If accepted $ _POST
var params = new URLSearchParams(); params.append('username', 'admin'); params.append('password', '123456'); axios.post('test.php', params).then(res => console.log(res.data));</script>
You can look at a document Using application / x-www-form-urlencoded format this paragraph
Other methods
It requires only small changes, like turning it into a string submitted.
var params = 'ajax='+encodeURIComponent(JSON.stringify({ username: 'admin', password: '123456' })); axios.post('test.php', params).then(res => console.log(res.data))
On the server side var_dump(json_decode(urldecode($_POST['ajax'])));
up.
If you want to simulate jQuery Ajax request, it is coupled with a config
var url = ... var params = 'ajax='+encodeURIComponent(JSON.stringify(...)); var config = {headers: {'X-Requested-With': 'XMLHttpRequest'}}; axios.post(url, params, config)...
Next in PHP, you can use your familiar with the IS_AJAX, isXmlHttpRequest like the