vue
因此交互使用的是官方推荐的axios
,在jquery
中使用ajax
时收发数据都没有问题,可是使用axios
的post
方法时发现一些问题,根据本身的理解记录一下。methods:{
axios_post:function(){
axios
.post('https://www.xxxxxx.cn/xx/xx.php',{
UserName:'xipengheng',
msg:'我是一头长颈鹿,我爱上树',
msgTime:'2019.10.23'
})
.then(res=>{
console.log(res);
})
}
},
复制代码
$UserName='"'.$_POST['UserName'].'"';
$msg='"'.$_POST['msg'].'"';
$msgTime='"'.$_POST['msgTime'].'"';
复制代码
PHP
中个人SQL
语句是没有数据的,所以也无法往数据库中存储数据
PHP
代码的状况下有什么解决办法呢?一、经过实例化一个FormData
把数据放入就能够了(推荐)。javascript
methods: {
axios_post:()=> {
var params = new FormData();
params.append('UserName', 'xipengheng');
params.append('msg', '我是一头长颈鹿,我爱上树');
params.append('msgTime', '2009.09.09');
axios
.post('https://www.xipengheng.cn/AAA/liuyan.php',params)
.then(res => {
console.log(res);
})
}
},
复制代码
qs
,利用数据转化为qs.stringtry({})
,也能够实现methods:{
axios_post:()=>{
axios
.post('https://www.xipengheng.cn/AAA/liuyan.php',qs.stringify({
UserName:'xipengheng',
msg:'我是一头长颈鹿,我爱上树',
msgTime:'2009.99.09'
}))
.then(res=>{
console.log(res);
})
}
},
复制代码