1
我需要用戶的sessionid進行服務器端身份驗證。因此,需要在每個請求的頭部中發佈Sessionid,而這些都是必不可少的。我正在使用以下在標題中發佈sessionId,但發生了錯誤。發生將sessionid添加爲POST請求使用ajax請求與framework7請求
apiservice.getProfileDetails = function(data, callback){
// $.cookie("sessionid", $.jStorage.get("sessionKey"));
document.cookie = "sessionid=" +$.jStorage.get("sessionKey");
console.log(document.cookie);
var requestEnvelope = {
url: apiservice.baseUrl + '/get/my/information/?callback='+callback,
xhrFields: {withCredentials: true},
crossDomain: true,
async: false,
type: 'POST',
// beforeSend : function(xhr) { var cookie = credentials["COOKIE"]; console.info("adding cookie: "+ $.jStorage.get("sessionKey")); xhr.setRequestHeader('Cookie', $.jStorage.get("sessionKey")); },
beforeSend: function (request)
{
request.setRequestHeader("Cookie", "sessionid=" +$.jStorage.get("sessionKey"));
},
// setCookies: $.jStorage.get("sessionKey"),
// headers: {"sessionid": $.jStorage.get("sessionKey")},
data: JSON.stringify(data),
complete: function(res){
ux.getProfileDetails(res.responseText);
}
}
$.ajax(requestEnvelope);
};
錯誤是jquery.min.js:4 Refused to set unsafe header "Cookie"
也試過來設置cookies在頭
headers: {"sessionid": $.jStorage.get("sessionKey")},
,但同樣的錯誤,任何解決方案