https协议下,post请求跨域,get请求没跨域,http协议没问题;
相关代码
3 回答

SMILET
TA贡献1796条经验 获得超4个赞
还是跨域的问题没有解决。
前端需要允许跨域,加入xhrFields,jQuery的话,大概这样:
$.ajax({
type: "POST",
xhrFields:{
withCredentials:true
},
success: function(){
}
});
后端加入header
header("Access-Control-Allow-Credentials", "true");
header("Access-Control-Allow-Origin", "允许跨域的地址,如果全部允许写*");

慕工程0101907
TA贡献1887条经验 获得超5个赞
// 使用通配符 * ,表示当前服务端 返回的信息允许所有源访问,也可指定可信任的域名来接收响应信息
header("Access-Control-Allow-Origin: http://localhost:3000");
header("Access-control-Allow-Origin:*");
// 响应头设置为ajax提交
header("Access-Control-Allow-Headers:X-Requested-With");
// 允许携带 用户认证凭据(也就是允许客户端发送的请求携带Cookie)
header("Access-Control-Allow-Credentials:true");
写到方法内部
- 3 回答
- 0 关注
- 3912 浏览
添加回答
举报
0/150
提交
取消