Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So here's something I find puzzling.

I'm working on a Javascript that needs to parse XML data and I'm using jQuery's $.ajax to fetch and parse the data. It's working great everywhere except when I test with Internet Explorer 8 (it might be a problem on 7 and 9 too). On IE, I'm getting parse errors. I installed a console.log to check the HTTP headers. Here's what I get from Chrome on Windows XP and what I'm getting from IE --

Chrome:

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

This is a sample of what the xml document looks like:

<?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>

I checked the MIME configuring for my Apache server and it is set to send xml files as 'application/xml'. So it's strangely sending a content-type of 'application/xml' to Chrome, but IE gets content-type of 'text/html'.

So I built a simple PHP script:

<?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>

When I change the Javascript to retrieve the PHP instead of the XML file, I get these response headers --

Chrome with 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 with 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

More strangeness I just discovered. I put an

AddType application/xml tweets

into my directives for that virtual server. When I then fetch my XML document with the .tweets extension, IE does get the correct content-type in the header! In fact, the header looks more like the Chrome version --

Chrome with .tweets file:

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 with .tweets file:

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

So from what I can tell, with my limited Apache knowledge, it seems like the raw XML file is getting sent without the right content-type only to IE, even though I have it configured to send 'application/xml'. Chrome is receiving the right content-type. When I use PHP, Apache seems to be following my wishes and sending 'application/xml' because that is what I stamped it as in the script. Is it also strange that IE doesn't have all the same headers as Chrome? "Server" is missing for instance. When I add a custom extension of .tweets, configured to use application/xml, I also get the correct content-type.

So what could possibly be getting in the way and changing 'application/xml' to 'text/html' only for Internet Explorer? I'd hate to have to rely on my workarounds. I thought of mod-deflate, but I disabled it and the results are the same.

Any ideas?

(PS - the XML I'm including is just a sample, so the content-lengths don't match up

share|improve this question

1 Answer 1

up vote 1 down vote accepted

So I think I figured it out.

It appears that IE caches the AJAX GET data in such a way that it is hard (impossible?) to clear it out. Maybe I had the xml configured as text/xml at some point, but I don't think so. Basically, IE continued to use the cached results for that XML file over the actual server results. That also explains why the HTTP headers looked so odd (no server information for instance). Or it's possible that the cache is always producing text/html (I gave up further tests).

My solution: I added a '?avoidcache=' + a timestamp to the end of the URL in the GET request. Now IE gets the proper HTTP headers that I set on the server.

Wow do I hate Internet Explorer. How many development hours are wasted creating workarounds for it's horrible behavior?

share|improve this answer
1  
My favorite solution to that problem is to not code workarounds for IE. If people use a bad browser the web should look ugly and be less useful for them. Sadly that's not an option for many web developers. –  chrishiestand Apr 12 '11 at 9:10
    
BTW, A technique I would have recommended is running something like tcpdump to capture raw reqeust/response headers. This way you can be certain of what your web server is sending without worrying about odd browser behaviors. –  chrishiestand Apr 12 '11 at 9:12
    
@dimmer - I WISH I could get away with that technique! I have been able to drop IE6 and on some sites I give IE7 users a warning and recommendation to install a proper web browser. –  JonMcL Apr 12 '11 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.