A few days ago, a friend of the program out of the problem but how to check all did not see problems, so let me help it look. In fact, it is an AJAX request for a number of templates, and then write the template to the page. The key is that all of the requested pages are 200 normal status code return, seemingly no problem, in fact, some requests, although return 200 status code, but give back the status code is 200. Webserver is nginx, just tell me that they configured the Nginx 404 error page, although the request nonexistent resources can successfully return 404 pages, but the return status code is indeed 200.
404.html
Copy Code code as follows:
To request a page that does not exist:
Ajax Code:
$.ajax ({
URL: "does_not_exist.html",
success:function (Response, textstatus) {
Console.log (Tex tstatus+ ":" +response);
},
error:function (XMLHttpRequest, Textstatus, Errorthrown) {
CONSOLE.L OG ([XMLHttpRequest, Textstatus, Errorthrown].join (","));
}
});
Execution results:
Enter object to see details:
Could not find the requested page and return 404 page information, but the status code is still 200, so jquery did not take the error
function callback but went directly to success
the callback.
There should be a problem with the configuration writing, so open nginx.conf and find that they are configured to write:
Copy Code code as follows:
Error_page 404 =/404.html;
So I looked at the official website document and rewrote the expression above to read:
Copy Code code as follows:
and then reboot.
Copy Code code as follows:
D:\nginx-1.5.11>nginx.exe-s Reload
Try again:
Let's look at the AJAX request:
Visible compared to the previous return marked red 404 status Code, the following Console.log out is
Copy Code code as follows:
[Object Object],error,not Found
Then click Enter object to see:
The status value is 404. Both the return of 404 pages, and the return of 404 status code so that AJAX requests can be based on the status code to determine the status of the page request error handling.
(End of this article)