前端:
以jquery為例:
需要加入
復(fù)制代碼 代碼如下:
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
});
服務(wù)器端:
以php為例:
復(fù)制代碼 代碼如下:
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Origin: http://m.z.com');
根據(jù)自己的情況而定
以上所述就是本文關(guān)于解決ajax跨域請求數(shù)據(jù)時cookie丟失的處理方案,希望大家能夠喜歡。
您可能感興趣的文章:- 跨域請求之jQuery的ajax jsonp的使用解惑
- AJAX跨域請求json數(shù)據(jù)的實現(xiàn)方法
- jQuery.ajax 跨域請求webapi設(shè)置headers的解決方案
- JQuery的Ajax跨域請求原理概述及實例
- jquery+ajax實現(xiàn)跨域請求的方法
- PHP處理Ajax請求與Ajax跨域問題
- Ajax跨域請求COOKIE無法帶上的完美解決辦法
- ajax跨域請求js拒絕訪問的解決方法
- jQuery使用ajax跨域請求獲取數(shù)據(jù)
- 用iframe設(shè)置代理解決ajax跨域請求問題
- Ajax請求跨域問題解決方案分析