Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
50
rated 0 times [  55] [ 5]  / answers: 1 / hits: 35095  / 11 Years ago, thu, september 12, 2013, 12:00:00

I'm looking for a list of http status codes in Javascript. Are they defined in any implementation?



I've had a look at XMLHttpRequest, but only found readyState constants.



var xhr = new XMLHttpRequest();
console.log(xhr.DONE); //4


I'm looking for something like



console.log(xhr.statusCodes.OK); //200


Which obviously doesn't exist on the xhr object.


More From » javascript

 Answers
49

Http status codes are maintained by the Internet Assigned Numbers Authority (IANA), whereas readyState is specific to XmlHttpRequest.



Therefore just go to a reputable source. The wikipedia article should suffice as this is not really a contentious topic - or, as commented, the official list can be found here



You could also wrap those you are interested in into a javascript object



var HttpCodes = {
success : 200,
notFound : 404
// etc
}


usage could then be if(response == HttpCodes.success){...}


[#75732] Wednesday, September 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tatumm

Total Points: 47
Total Questions: 92
Total Answers: 89

Location: Palau
Member since Tue, May 30, 2023
1 Year ago
;