我已经在我当前的项目中使用了 CORS,尽管我似乎无法正常工作的一件事是 cookie。
现在我得到了 cookie,服务器发出它并将其发送下来,firefox 接受它,我可以在 firebug cookies 部分看到它。然而,当我对该服务进行后续调用时,它似乎没有在标头中发送 cookie...
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
我需要对我的 ajax 调用做一些特别的事情吗?
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
xhrFields: { withCredentials: true }
};
$.ajax(ajaxOptions);
尝试使用 beforeSend 属性而不是 xhrFields。在你的情况下:
var ajaxOptions = {
url: serviceResourceUrl,
type: "get",
dataType: "json",
success: successCallback,
error: failedCallback,
beforeSend: function(xhr){
xhr.withCredentials = true;
}
};
$.ajax(ajaxOptions);
您可以在这里了解更多信息:通过跨域帖子发送凭据? https://stackoverflow.com/questions/2054316/jquery-sending-credentials-with-cross-domain-posts
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)