jQuery的阿贾克斯CORS +仅Http饼干 [英] Jquery Ajax CORS + HttpOnly Cookie
问题描述
我有CORS工作对我目前的项目,但有一件事我似乎无法得到正常工作的饼干。
现在我得到的饼干很好,服务器的问题,并把它发送下来,Firefox的接受它,我可以看到它在萤火虫的Cookie部分。然而,当我进行后续调用该服务似乎犯规发送的cookie的头...
GET /一些/实体/ HTTP / 1.1
主持人:本地主机:1837
用户代理:Mozilla的/ 5.0(Windows NT的6.1; WOW64; RV:5.0)的Gecko / 20100101火狐/ 5.0
接受: */*
接受语言:EN-GB,EN; Q = 0.5
接受编码:gzip,紧缩
接收字符集:ISO-8859-1,UTF-8,Q = 0.7,*; Q = 0.7
连接:保持活动
引用站点:HTTP://本地主机:6879
原产地:HTTP://本地主机:6879
我需要做什么特别的事情与我的AJAX调用?
VAR ajaxOptions = {
网址:serviceResourceUrl,
键入:搞定,
数据类型:JSON,
成功:successCallback,
错误:failedCallback,
xhrFields:{withCredentials:真}
};
$阿贾克斯(ajaxOptions);
尝试使用beforeSend属性而不是xhrFields。你的情况:
VAR ajaxOptions = {
网址:serviceResourceUrl,
键入:搞定,
数据类型:JSON,
成功:successCallback,
错误:failedCallback,
beforeSend:功能(XHR){
xhr.withCredentials = TRUE;
}
};
$阿贾克斯(ajaxOptions);
您可以了解更多点击这里:<一href="http://stackoverflow.com/questions/2054316/jquery-sending-credentials-with-cross-domain-posts">jQuery:发送凭据与跨域职位?
I have got CORS working on my current project, although one thing I cannot seem to get working correctly is the cookies.
Now I get the cookie fine, the server issues it and sends it down and firefox accepts it, I can see it in the firebug cookies section. However when I make subsequent calls to that service it doesnt seem to send the cookie in the header...
GET /some/entity/ HTTP/1.1
Host: localhost:1837
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: */*
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost:6879
Origin: http://localhost:6879
Do I need to do anything special with my ajax call?
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
xhrFields: { withCredentials: true }
};
$.ajax(ajaxOptions);
Try using the beforeSend property instead of xhrFields. In your case:
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
beforeSend: function(xhr){
xhr.withCredentials = true;
}
};
$.ajax(ajaxOptions);
You can learn more here: jQuery: sending credentials with cross-domain posts?
这篇关于jQuery的阿贾克斯CORS +仅Http饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!