这似乎是101级,但我找不到答案!(相反,我找到了成功或失败,jQuery ajax().success等的链接.
我的预感是:
success:200 HTTP返回码failure: 还要别的吗.这不是真正的AJAX,而是jQuery问题,因为成功回调只是jQuery的特征,而不是整体上的AJAX.
从jQuery源代码中,您可以看到它是如何实现的
// If successful, handle type chaining
if ( status >= 200 && status < 300 || status === 304 ) {
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
jQuery.lastModified[ ifModifiedKey ] = lastModified;
}
if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
jQuery.etag[ ifModifiedKey ] = etag;
}
}
// If not modified
if ( status === 304 ) {
statusText = "notmodified";
isSuccess = true;
...
else fail with the error callback
Run Code Online (Sandbox Code Playgroud)
所以,基本上如果HTTP响应代码在200到299(含)之间或304则用于success回调,否则,它就是error回调.