Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX returns unusual status codes

So I've finally gotten around to trying AJAX again (rather than hidden iframes), and I now remember why I hated AJAX so much in the first place.

It's a simple script that queries the server for the number of private messages the user has received. The server responds with a single number, and the script updates the indicator and sets a timeout for five seconds to query again.

On rare occasion (usually when I go AFK for a while), I start getting the most bizarre HTTP status codes.

On Chrome: "AJAX request failed to retrieve /ajax/network.php, HTTP status 0"
On IE: "AJAX request failed to retrieve /ajax/network.php, HTTP status 12029"

Neither of these codes are valid. What's going on here, and how can I stop it from happening?

like image 818
Niet the Dark Absol Avatar asked Sep 28 '11 23:09

Niet the Dark Absol


1 Answers

That is an annoying aspect of AJAX. I find it's best to simply treat all non-200 statuses as an error. Really, you're not going to show your users any specific error messages relating to the actual result ("A problem has occurred"), so I'd simply not worry overly about inconsistent error conditions.

jQuery normalizes some of the AJAX behavior, so you may also want to look into using that.

By the way, error 0 in Chrome and 12029 in IE indicate connection problems; since that has nothing to do with HTTP, that's why invalid codes are shown.

like image 96
Jacob Avatar answered Sep 25 '22 02:09

Jacob