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