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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM