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);
posted @ 2021-12-15 14:31  nxmxl  阅读(844)  评论(0编辑  收藏  举报