时间:2021-07-01 10:21:17 帮助过:4人阅读
网上大概搜了下,
写道
原生ajax请求方式:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);
xhr.withCredentials = true; //支持跨域发送cookies
xhr.send();jquery的ajax的post方法请求:
$.ajax({
type: "POST",
url: "http://xxx.com/api/test",
dataType: 'jsonp',
xhrFields: {
withCredentials: true
},
crossDomain: true,
success:function(){
},
error:function(){
}
})服务器端设置:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");
后端进行了相应的调整,前端这块因为涉及到 fineuploader,在其代码中简单搜索了下关键字 withCredentials,然后去官方看了下文档,存在 cors 的配置 http://docs.fineuploader.com/api/options.html#cors
在配置行中加入以下配置 就ok了
Js代码
cors: {
allowXdr: true,// 此参数目前不知道有啥用
expected: true,
sendCredentials: true
}修改之后,问题解决.