前端:
以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跨域請(qǐng)求數(shù)據(jù)時(shí)cookie丟失的處理方案,希望大家能夠喜歡。
您可能感興趣的文章:- 跨域請(qǐng)求之jQuery的ajax jsonp的使用解惑
- AJAX跨域請(qǐng)求json數(shù)據(jù)的實(shí)現(xiàn)方法
- jQuery.ajax 跨域請(qǐng)求webapi設(shè)置headers的解決方案
- JQuery的Ajax跨域請(qǐng)求原理概述及實(shí)例
- jquery+ajax實(shí)現(xiàn)跨域請(qǐng)求的方法
- PHP處理Ajax請(qǐng)求與Ajax跨域問題
- Ajax跨域請(qǐng)求COOKIE無法帶上的完美解決辦法
- ajax跨域請(qǐng)求js拒絕訪問的解決方法
- jQuery使用ajax跨域請(qǐng)求獲取數(shù)據(jù)
- 用iframe設(shè)置代理解決ajax跨域請(qǐng)求問題
- Ajax請(qǐng)求跨域問題解決方案分析