奇怪的HTTP响应头只被发送到Internet Explorer 8

所以这是我觉得困惑的东西。

我正在研究一个需要parsingXML数据的Javascript,我使用jQuery的$ .ajax来获取和parsing数据。 除了使用Internet Explorer 8进行testing(这可能是7和9的问题)之外,它在任何地方都很好用。 在IE浏览器,我得到parsing错误。 我安装了一个console.log来检查HTTP标头。 这是我从Windows XP上的Chrome获得的内容,以及我从IE获得的内容 –

铬:

Date: Sat, 09 Apr 2011 16:06:24 GMT Connection: Keep-Alive Content-Length: 2283 Last-Modified: Sat, 09 Apr 2011 15:59:12 GMT Server: Apache/2.2.14 (Ubuntu) ETag: "48048-8eb-4a07e6c693400" Content-Type: application/xml Accept-Ranges: bytes Keep-Alive: timeout=15, max=97 

IE8:

 LOG: ETag: "48048-8eb-4a07d7a3cbe40" Keep-Alive: timeout=15, max=97 Content-Type: text/html Content-Length: 2283 Last-Modified: Sat, 09 Apr 2011 14:51:29 GMT 

这是xml文档的样例:

 <?xml version="1.0" encoding="UTF-8"?> <root> <tweet> <name>name</name> <message>message</message> <avatar>avatar</avatar> </tweet> <tweet> <name>name</name> <message>message</message> <avatar>avatar</avatar> </tweet> </root> 

我检查了我的Apache服务器的MIMEconfiguration,并将其设置为以“application / xml”的forms发送xml文件。 所以奇怪的是向Chrome发送一个内容types的'application / xml',但是IE获取'text / html'的内容types。

所以我build立了一个简单的PHP脚本:

 <?php header('Content-type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?> <root> <tweet> <name>name</name> <message>message</message> <avatar>avatar</avatar> </tweet> <tweet> <name>name</name> <message>message</message> <avatar>avatar</avatar> </tweet> </root> 

当我更改Javascript来检索PHP而不是XML文件时,我得到这些响应头 –

Chrome与PHP:

 Date: Sat, 09 Apr 2011 16:10:39 GMT X-Powered-By: PHP/5.2.10-2ubuntu6.7 Connection: Keep-Alive Content-Length: 2102 Server: Apache/2.2.14 (Ubuntu) Content-Type: application/xml; charset=UTF-8 Keep-Alive: timeout=15, max=97 

IE与PHP:

 LOG: X-Powered-By: PHP/5.2.10-2ubuntu6.7 Content-Length: 2102 Keep-Alive: timeout=15, max=100 Content-Type: application/xml; charset=UTF-8 

我刚刚发现了更多的陌生感。 我把一个

 AddType application/xml tweets 

进入我的虚拟服务器的指令。 然后,当我用.tweets扩展名获取我的XML文档时,IE会在标题中得到正确的内容types! 事实上,标题看起来更像是Chrome版本 –

Chrome与.tweets文件:

 Connection: Keep-Alive Content-Length: 2102 Last-Modified: Sat, 09 Apr 2011 16:33:46 GMT Server: Apache/2.2.14 (Ubuntu) ETag: "48048-836-4a07ee807ee80" Content-Type: application/xml Accept-Ranges: bytes Keep-Alive: timeout=15, max=100 

IE与.tweets文件:

 LOG: Date: Sat, 09 Apr 2011 16:38:56 GMT Server: Apache/2.2.14 (Ubuntu) Last-Modified: Sat, 09 Apr 2011 16:33:46 GMT ETag: "48048-836-4a07ee807ee80" Accept-Ranges: bytes Content-Length: 2102 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: application/xml 

所以从我可以告诉的是,用我有限的Apache知识,似乎原始的XML文件发送没有正确的内容types只有IE浏览器,即使我已经configuration为发送“应用程序/ XML”。 Chrome正在接收正确的内容types。 当我使用PHP时,Apache似乎遵循我的意愿并发送'application / xml',因为这是我在脚本中加盖的。 IE浏览器没有与Chrome相同的头文件也很奇怪吗? 例如,“服务器”缺失。 当我添加.tweets的自定义扩展,configuration为使用application / xml,我也得到正确的内容types。

那么有什么可能会阻碍Internet Explorer的“application / xml”更改为“text / html”呢? 我讨厌必须依靠我的解决方法。 我想到mod-deflate,但我禁用它,结果是一样的。

有任何想法吗?

(PS – 我所包含的XML只是一个示例,所以内容长度不匹配

所以我想我明白了。

IE浏览器cachingAJAX GET数据的方式很难(不可能)清除掉。 也许我在某个时候将xmlconfiguration为text / xml,但我不这么认为。 基本上,IE继续在实际的服务器结果上使用该XML文件的caching结果。 这也解释了为什么HTTP头看起来很奇怪(例如没有服务器信息)。 或者有可能caching总是生成文本/ HTML(我放弃了进一步的testing)。

我的解决scheme:我在GET请求的URL末尾添加了一个'?avoidcache ='+时间戳。 现在,IE获取正确的HTTP头,我在服务器上设置。

哇,我讨厌Internet Explorer。 浪费了多less个开发时间,为它的可怕行为创造解决方法?