美文网首页
axios发送post 请求 PHP接受数据的方式

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

作者: RedStones | 来源:发表于2021-04-22 14:16 被阅读0次

前端js

axios.post('post.php', {
      name:"axios",
      pass:'123456x'
  })
  .then(function (response) {
    console.log('1>', response.data);
  })
  .catch(function (error) {
    console.log(error);
  });

后端php

<?php
#header("content-type:text/html;charset=utf-8"); #返回字符串
#header('Content-Type:application/json; charset=utf-8'); #返回json

$data = (array)json_decode($HTTP_RAW_POST_DATA);
#$data=(file_get_contents('php://input')) ; //获取非表单数据;
#file_put_contents("../dustbin/post.txt", $data);

$_POST=$data;
$name=  $_POST["name"];
$pass= $_POST["pass"];

//返回json
echo json_encode($_POST);

相关文章

网友评论

      本文标题:axios发送post 请求 PHP接受数据的方式

      本文链接:https://www.haomeiwen.com/subject/jyaxrltx.html