search

Home  >  Q&A  >  body text

javascript - axios upload data to php returns empty

1.vue 2.0 uses axios to upload data and returns empty, and the background is php

2.vue code

saveEssay(){
        console.log(this.titleData);
        this.axios({
          method: 'post',
          url:'XXX',
          data: {
            title: this.titleData,
            tags: this.tagsData,
            content:this.contentData,
            isPublish:0
          }
        })
          .then(function (response) {
            console.log(response);
          })
          .catch(function (error) {
            console.log(error);
          })
      },

3.php code

<?php
header('Content-type:text/html;charset=utf8');  
header('Access-Control-Allow-Origin:*');  
 
header('Access-Control-Allow-Methods:POST');  

header('Access-Control-Allow-Headers:x-requested-with,content-type');  
$mysqli=new mysqli();
$mysqli->connect('xxx','xxx','xxx','xxx');
if (mysqli_connect_errno($mysqli))
{
    echo "连接 MySQL 失败: ";
}
$v1=$_REQUEST['title'];
$v2=$_REQUEST['tags'];
$v3=$_REQUEST['content'];
$v4=$_REQUEST['isPublish'];
 echo $v1.$v2.$v3.$v4
?> 

4.console returns data

   ![图片描述][1]

5. Remarks
Get data is valid. Post submission data cannot be obtained for some reason in the php page, and the return is empty. The html page can be accessed and can also be inserted into the database, but it is empty. And it is possible to simply upload data to php using jQuery. The only difference between the two is the method of uploading data. Ask God for answers

过去多啦不再A梦过去多啦不再A梦2703 days ago958

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-20 10:07:38

    file_get_contents("php://input")

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-20 10:07:38

    Search to Baidu and PHP cannot obtain data in json format

    reply
    0
  • Cancelreply