Apache和Headers存在以响应Ajax请求

时间:2014-07-07 12:10:08

标签: ajax apache header cross-domain cors

我试图弄清楚跨域API问题。 我有一个使用Sencha Touch 2.3.1创建的应用程序,它使用Ajax从远程服务器获取数据。 我面临的问题是针对本地服务器的所有Ajax请求都不包含响应中的所有标头。 在远程服务器上,一切正常,标题正常。

以下两张打印件显示了每个服务器单独发送和接收的标题

1 - 从localhost(http://local.api - vhost)发送和接收的标头

收到了标题:

Connection      Keep-Alive
Content-Length  274
Content-Type    text/html; charset=iso-8859-1
Date            Mon, 07 Jul 2014 10:58:54 GMT
Keep-Alive      timeout=5, max=100
Location        http://local.api/fa/?ref.agent/lista-clienti&_dc=1404730734262
Server          Apache/2.2.17 (Win32) PHP/5.3.3

发送的标题:

Accept          text/html,application/xhtml+xml,
                application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
Content-Length  33
Content-Type    application/x-www-form-urlencoded; charset=UTF-8
Host            local.api
Origin          http://sencha.local
Referer         http://sencha.local/fisa-agenti/index.html
User-Agent      Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 
                Firefox/30.0

2 - 从远程服务器(http://adgarage.ro)发送和接收的标头

收到标题

Accept-Ranges                   bytes
Access-Control-Allow-Cred...    true
Access-Control-Allow-Orig...    *
Age                             0
Connection                      keep-alive
Content-Length                  375
Content-Type                    application/json
Date                            Mon, 07 Jul 2014 10:58:52 GMT
Server                          Apache/2.2.22 (Unix) mod_ssl/2.2.22 
                                OpenSSL/0.9.8e-fips-rhel5
Via                             1.1 varnish
X-Powered-By                    PHP/5.3.13
X-Varnish                       562862498

已发送标题

Accept          text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
Host            adgarage.ro
Origin          http://sencha.local
Referer         http://sencha.local/fisa-agenti/index.html
User-Agent      Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 
                Firefox/30.0

请注意Access-Controll-Allow标题。 从localhost

收到的标头容器中缺少它

这是我的.htaccess文件:

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

这两个服务器上的文件是相同的。 我在本地计算机上有headers_module acitive。

我注意到的另一件事是来自本地的响应状态为301 moved Permanently,而从远程服务器收到的响应状态为200 Ok

我缺少什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我发现了问题所在。 正如此this topic标题中所述,由于301 Moved Permanently状态而未发送。

我的本​​地请求是http://local.api/fa?ref.agent/...而不是http://local.api/fa/?ref.agent/... - 请注意第一个链接中/fa后丢失的尾部斜杠。

现在一切都还可以。