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