var params = { username: 'admin', password: '123456' } axios.post('test.php', params).then(res => console.log(res.data))
php代碼以下javascript
//傳的是一個json對象,能夠用file_get_contents("php://input")獲取到json串,而後轉化爲object獲取屬性 $data = file_get_contents("php://input");
若是用$_POST接受php
var params = new URLSearchParams(); params.append('username', 'admin'); params.append('password', '123456'); axios.post('test.php', params).then(res => console.log(res.data));</script>
能夠看下文檔 Using application/x-www-form-urlencoded format這個段落
其餘方法java
只須要很小的改動,把它變成字符串提交就好。ios
var params = 'ajax='+encodeURIComponent(JSON.stringify({ username: 'admin', password: '123456' })); axios.post('test.php', params).then(res => console.log(res.data))
在服務器端 var_dump(json_decode(urldecode($_POST['ajax'])));
了。ajax
若是是要模擬jQuery的Ajax請求,就再加個configjson
var url = ... var params = 'ajax='+encodeURIComponent(JSON.stringify(...)); var config = {headers: {'X-Requested-With': 'XMLHttpRequest'}}; axios.post(url, params, config)...
接下來在PHP裏,就能夠用你熟悉的的IS_AJAX、isXmlHttpRequest之類的了axios