1、后端及web服务没做过跨域设置
2、看过跨域文章,但是对跨域发生场景还是不清楚有时会碰到有时有不会
2019-08-30 14:47修改问题
经测试在请求头为Content-Type:application/x-www-form-urlencoded时正常返回数据
axios({
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "post",
url:
"https://bdapp.***.cn/api.php/portal/lists/getCategoryPostLists",
data: param
}).then(function(res) {
console.log(res.data);
});
将请求头改为Content-Type: application/json后返回分类不存在,并且返回options
另外,在api.php添加下面代码后不能解决options没有返回数据问题
header('Access-Control-Allow-Origin:'); //允许跨域请求的域名地址 可以为表示接受所有地址
header('Access-Control-Allow-Methods:*'); //允许的请求方式
header('Access-Control-Allow-Credentials:true'); //可选 是否允许客户端提交cookie![]()
get请求应该是不跨域的吧,试试post(传递json)?
即简单请求和非简单请求。非简单请求才会跨域