问题:php接口,用ajax请求可以请求到数据,用axios请求不到。
axios
代码:
getJson(){
this.axios({
method:'post',
url:'vip/index.php',
data:{
'name':'qq.com',
'videoUrl':'https://v.qq.com/detail/6/639agzdh10yu2q2.html'
}
}).then(res=>{
//console.log(res.data);
this.msg = res.data;
console.log(this.msg)
})
}
截图

ajax
代码:
$.ajax({
url:'http://127.0.0.1:8088/vip/index.php',
type:'post',
data:{name:'qq.com',videoUrl:'https://v.qq.com/detail/6/639agzdh10yu2q2.html'},
dataType:'json',
success:function(data){
console.log(data)
},
error:function(){
console.log('error')
}
})
截图:


在尝试从PHP接口获取数据时,使用Ajax进行POST请求能够成功获取到数据,但使用Axios进行相同操作时却无法接收到响应数据。问题可能涉及到请求头、数据序列化或者跨域配置等。对于Ajax请求,数据成功返回并在控制台打印;而对于Axios,没有数据返回,也没有错误信息。

333

被折叠的 条评论
为什么被折叠?



