About software, technology and random things


AJAX with Chrome – empty responseText

Hi there!

When I implemented AJAX today in a new script of mine and persuaded 😛 a couple of friends of mine to visit the page, I found that the Chrome users received error messages when trying to use the AJAX functions. However, they actually worked. The server received the AJAX request and processed it correctly, leaving me scratching my head.

Turns out that Chrome only received an empty AJAX response in responseText which caused the JavaScript function to throw out an error message. But why was it empty?

A couple of web searches later I realized that apparently not too many people had come across that problem. Luckily enough I found a post in a forum that pushed me in the right direction.

Chrome seems to be a little sensitive concerning headers in the AJAX responses. Because I hadn't given my server-side AJAX processing script the appropriate "Content-Type: text/plain" header, it didn't "accept" the response as text.

Why it has to be so picky, however, I cannot understand 🙂

If you have encountered that problem before, I hope I managed to help you out.

Certainly made me go a little crazy for a while there 😛

Comments (0) Trackbacks (0)
  1. Interesting!

    Thanks for sharing that 🙂

  2. With text/plain, you must also have 1024 bytes before streaming starts to work (i.e. before the first call to onreadystatechange()). In PHP, this line at the top of your script can achieve that:
    echo str_repeat(“\n”,1024); //For Chromium.

  3. thanks man you save my weekend greetings from cuba

  4. Make sure you send the following header in the PHP source code:
    header ("Content-Type: text/plain");
    before sending anything else (except other headers).
    For more information, visit

    Other languages than PHP of course use different methods for sending HTTP headers, but I hope you get the idea 🙂

  5. how do you change the content-type to text plain in the response header?

Leave a Reply

No trackbacks yet.