3

我想使用 POST 提供跨域服务。我可以看到 preflight OPTIONS 调用成功,但是当我发布时,cookie 没有在 Chrome 中发送。相同的 javascript 和服务器代码适用于 Firefox 和 Safari。可能是什么问题呢?以下是详细信息:

请求 URL:http://j.test.com/Post
请求方法:OPTIONS
状态码:200 OK
请求标头view source
Accept: /
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q =0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-requested-with, content-type, accept
Access-Control-Request -方法:POST
连接:keep-alive
主机:j.test.com
来源:http://www.amazon.com参考
:http://www.amazon.com/Gone-Girl-A-Novel-ebook/dp /B006LSZECO/ref=pd_rhf_gw_s_ts_2
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11

响应头
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin, x-requested-with, content-type, accept
Access-Control-Allow-Methods:POST, OPTIONS
Access-Control-Allow-Origin :http://www.amazon.com
Access-Control-Max-Age:1728000
Connection:keep-alive
Content-Length:0
Date:Tue, 04 Sep 2012 16:44:48 GMT
服务器:nginx

我使用 jQuery:

  jQuery.ajax({
     type: "POST",
     url: "http://j.test.com/Post",
     xhrFields: {
        withCredentials: true
     },
     data: {
            referringUrl: document.URL
           },
     success: function(data) {
     },
     error: function (responseData, textStatus, errorThrown) {
     }
  });
4

2 回答 2

0

您必须将标志 withCredentials 设置为 true ( http://techblog.constantcontact.com/software-development/using-cors-for-cross-domain-ajax-requests/ )

于 2013-07-02T09:08:09.840 回答
0

您可能还需要crossDomain: true在您的jQuery.ajax()电话中。

于 2013-09-06T18:49:29.807 回答