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
file_get_contents("php://input")
Search to Baidu and PHP cannot obtain data in json format