javascript - axios上傳數(shù)據(jù)到php返回為空
問題描述
1.vue 2.0使用axios上傳數(shù)據(jù)返回為空,后臺為php
2.vue代碼
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代碼
<?phpheader(’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返回數(shù)據(jù)
![圖片描述][1]
5.備注get獲取數(shù)據(jù)是有效的,post提交數(shù)據(jù)不知為何在php頁面數(shù)據(jù)獲取不到,返回為空,html頁面可以訪問到,也可以插入到數(shù)據(jù)庫,只不過為空,而且 使用jQuery單純上傳數(shù)據(jù)到php是可以的,這兩者只差在了上傳數(shù)據(jù)的方法上。求大神解答
問題解答
回答1:file_get_contents('php://input')
回答2:自行百度,php獲取不到j(luò)son格式的數(shù)據(jù)
相關(guān)文章:
1. javascript - JS new Date() 保存到 mongodb 中會早8個小時,我們這里是東八區(qū),mongodb 保存的是格林尼治時間2. android百度地圖定位問題3. java - 判斷數(shù)據(jù)在數(shù)據(jù)庫中是否已存在.4. python - django models 為生成的html元素添加樣式。5. javascript - 關(guān)于圣杯布局的一點疑惑6. android - 圖片列表分組之后復(fù)用問題7. android - 有數(shù)據(jù)要處理的時候如何使用rxJava進行異步處理數(shù)據(jù)8. nginx bind failed9. 為什么我寫的PHP不行10. css - input間的間距和文字上下居中

網(wǎng)公網(wǎng)安備