前端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')) ; //获取非表单数据;
#file_put_contents("../dustbin/post.txt", $data);
$_POST=$data;
$name= $_POST["name"];
$pass= $_POST["pass"];
//返回json
echo json_encode($_POST);