blog.plee.me About software, technology and random things

5Aug/090

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 😛