axios发送post 请求 PHP接受数据的方式

JS

axios.post('http://localhost/comments/post.php', {
      a: 10
    }).then(res => {
      console.log(res)
    })

php

<?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);
原文地址:https://www.cnblogs.com/nxmxl/p/15692658.html