解决ajax跨域请求数据cookie丢失问题
前端:
以jquery为例:
需要加入
xhrFields:{
withCredentials:true
},
crossDomain:true,
$.ajax({
type:postType,
url:url,
data:postData||'',
xhrFields:{
withCredentials:true
},
crossDomain:true,
success:function(){
successCallback.apply(scope||this,arguments);
},
failureCallback:function(){
failureCallback.apply(scope||this,arguments);
},
dataType:dataType
});
服务器端:
以php为例:
header("Access-Control-Allow-Credentials:true");
header('Access-Control-Allow-Origin:http://m.z.com');
根据自己的情况而定
以上所述就是本文关于解决ajax跨域请求数据时cookie丢失的处理方案,希望大家能够喜欢。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短