0xDECAFBAD 0xDECAFBAD - 18 days ago 5
jQuery Question

Why is the JQuery status callback parameter a string rather than a number?

Is there any reason why the status callback parameter called

textStatus
of the
complete
and
error
functions, which themselve are defined on the
jqXHR
object, is a string? I would expect the status to be a number (besides the name, which already suggests the parameter to be a string).

Answer

Why would it be a number?

jQuery returns the following values in the textStatus argument

  • success
  • notmodified
  • nocontent
  • error
  • timeout
  • abort
  • parsererror

These are all custom messages in jQuery to tell what you wen't wrong, or if the request succeeded.

Any errors the server sends, such as a 404 Not Found or 403 Forbidden are generally considered successful requests by jQuery.

The custom error codes above are thrown by jQuery when for instance a request times out after a specific time has been reached, or if the content couldn't be parsed by jQuery etc.
These strings aren't part of the original XMLHttpRequest, but are added by jQuery as a convenience.