jQuery | Ajax | xhr.statusText: 'OK' vs xhr.status: 200

-1

In the jQuery ajax, I need a xhr.statusText:'OK' and throw a 'success' .

I also throw a xhr.status:200 serves the same?

  • Example:

if (xhr.statusText == 'OK' || xhr.status == 200) { // Ok! It works! Let's do something... });

    
asked by Lucas Moreno 26.10.2018 в 15:54
source

1 answer

2

Dear,

200 is the HTTP STATUS OK response of a http request, I add as a reference the list of status codes http: link

It is always better to compare state codes, and not its descriptive text, since it could be modified by the server that sends it.

In an ajax call, if the xhr.status == 200, it means that the server response was correct, but you must analyze the content to validate the data returned are the ones you need.

Greetings!

    
answered by 26.10.2018 / 16:10
source