使用xhrFields时的状态代码= 0:{withCredentials:true}在使用Firefox的jQuery $ ajax调用中

时间:2012-06-29 21:44:16

标签: jquery ajax firefox cookies cors

我正在使用

xhrFields : { 
  withCredentials: true 
} 

在jQuery $ ajax调用中,以便在我的查询中发送会话cookie。

该调用在我的apache日志中提供了正确的状态代码(401/200取决于是否设置了cookie),但Firefox总是收到状态= 0(即$ .ajax()中的错误) 如果我删除此xhrFields部分,状态代码就可以了(但不发送cookie)

这是我在Firefox中使用xhrFields设置收到的响应对象:

{"readyState":0,"responseText":"","status":0,"statusText":"error"}

我的Apache配置启用了CORS,并且还允许Access-Control-Allow-Credentials(这里是相应的HTTP头)

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *

在AJAX调用或webserver配置中是否缺少某些内容?

注意:这在Chrome中完全正常

1 个答案:

答案 0 :(得分:10)

您可能必须比*。

更明确地指定Access-Control-Allow-Origin标头

https://developer.mozilla.org/En/HTTP_access_control#Requests_with_credentials说:

  

重要说明:在响应凭证请求时,服务器   必须指定一个域,并且不能使用野外梳理。

相关问题