- Request and Response
- The Ready State
- Request Status
- ResponseText and ResponseXML
Request Status
The request status of the AJAX object is equivalent to the HTTP status of the file that’s being requested. The HTTP object that’s included in the AJAX file handles all of the HTTP Status Code Definitions outlined by the W3C, and returns them to the requesting method. The status codes are split into five categories:
The numbers represent the first number of the status codes from that category. For instance, Successful is 2xx, which means that it includes all of the status codes in the 200’s. The HTTP object checks for the first number of the status code and performs a switch, depending on the category to which the code belongs. After determining the category, the HTTP object sends it to the corresponding method, which returns the status code as a string. This is the HTTP status method:
this.status = function(_status) { var s = _status.toString().split(""); switch(s[0]) { case "1": return this.getInformationalStatus(_status); break; case "2": return this.getSuccessfulStatus(_status); break; case "3": return this.getRedirectionStatus(_status); break; case "4": return this.getClientErrorStatus(_status); break; case "5": return this.getServerErrorStatus(_status); break; } }
The status code is being handled by splitting it to determine the first number in the code. Once the code has been determined, the original status code is sent to the appropriate method, which returns a string version of the status code to the onResponse method. This message can then be displayed to the user, so that he or she has an understanding of what happened if something went wrong. If the request is successful, on the other hand, the data can be rendered.