Reputation: 151196
what is the correct way to determine that an AJAX call is successful?
I see in prototype.js
return !status || (status >= 200 && status < 300);
and in jQuery:
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
return !xhr.status && location.protocol == "file:" ||
( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223;
which one is correct? If we don't use any Javascript library but write the AJAX in basic Javascript, which one should we use?
Upvotes: 1
Views: 181
Reputation: 26583
HTTP statuses fall into these categories:
2XX: success
3XX: redirect
4XX: client error
5XX: server error.
So 200-300 is an "ok" result for an ajax call.
for more details on status codes, check out http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
cheers,
jrh.
Upvotes: 1
Reputation: 25707
Prototype seems more 'correct' as it only treats valid HTTP success codes as success. jQuery is more robust as it takes account of bugs and other things that are frequently success codes.
Upvotes: 5