您的位置:首页 > 其它

ajax跨域以及cookie丢失问题解决

2015-02-28 17:16 766 查看
前端:

以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: ' target='_blank'>http://m.z.com');[/code] 
根据自己的情况而定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: