axios发送post 请求 PHP接受数据的方式
2019-03-19 本文已影响0人
皇甫圣坤
axios.post('http://localhost/comments/post.php', {
a: 10
}).then(res => {
console.log(res)
})
<?php
//json头
header("Content-type: application/json");
//跨域
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *");
//CORS
header("Access-Control-Request-Methods:GET, POST, PUT, DELETE, OPTIONS");
header('Access-Control-Allow-Headers:x-requested-with,content-type,test-token,test-sessid');//注意头部自定义参数不要用下划线
// $a = $_POST['a'];
$a = json_decode($HTTP_RAW_POST_DATA);
print_r($a->a);