前端js
axios.post('post.php', {
name:"axios",
pass:'123456x'
})
.then(function (response) {
console.log('1>', response.data);
})
.catch(function (error) {
console.log(error);
});
后端php
<?php
#header("content-type:text/html;charset=utf-8"); #返回字符串
#header('Content-Type:application/json; charset=utf-8'); #返回json
$data = (array)json_decode($HTTP_RAW_POST_DATA);
#$data=(file_get_contents('php://input')) ; //獲取非表單數(shù)據(jù);
#file_put_contents("../dustbin/post.txt", $data);
$_POST=$data;
$name= $_POST["name"];
$pass= $_POST["pass"];
//返回json
echo json_encode($_POST);