Empty POST with IE 7 and ajax


Ok, so I moved to a new host last week (this site will move there shortly) and I transferred my project there. Several days later I noticed some of the ajax-requests were not getting any response, but only in IE7.

I first develop on FireFox and then test it on the other browsers. Because the problem is very irradic I didn't notice it immediately.

What happened was that sometimes at the beginning of a browsersession the ajax request would not receive a response from Apache. At least, it seemed to be that way untill I for some reason did not navigate away or refreshed that page after the problem and received data after 90 seconds. Although it wasn't quite the response I anticipated.

More tests showed that when the problem occurred, it would always reply after 90 seconds. Aha, a pattern at last. Next thing it showed that the POST variable was empty. No POST data appeared to be sent.

A packetsniffer told me otherwise though. A seemingly proper HTTP POST request was being sent from IE7, looking identical to FireFox'es with the exception of a few headers (but hey, they're just headers, right?). That's when you start doubting yourself...

Eventually I was unable to figure out the source of the problem, except that it wasn't IE7 (the request was sent) and not PHP (access logs showed that) and nothing of in the .htaccess file was to blame (disabled it).

Searching for the problem proved to be very difficult. But after being put on a false trail I finally found a page that led me to this page: http://www.modwest.com/help/kb2-260.html

Now I know all of that is old IE 6 crap. In fact, I dismissed the page the first time. But the second reply below contains a .htaccess line I eventually ended up testing. And ... it worked. Low and behold, the problem seemed to have disappeared (which is the problem with irradic bugs, you don't know whether you fixed it or moved it).

Anyways, after that I found something on Apache about keepalive and POST and how a POST request should not receive any more data after it's done. Well I figured it out. IE was sending a keepalive header (even though I was explicitly telling ajax to disable keepalive) and screwing it up in the process. Apache waits for 90 seconds then timeouts and just decides to proceed and discard all of the POST data. Apparantly my server is more sensitive to this problem than my previous one.

This is my solution:

Code: (htaccess)
<Limit POST>
SetEnv nokeepalive

This will disable keepalive for any POST request, but not change it for GETS or whatever (which is not a problem because you're meant to close POST requests anyways).

Hope this helps. This is probably one of the weirdest and toughest bugs I've encountered lately...