gpt4 book ai didi

jquery - 什么是 Ajax 调用 : 'success' or 'failure' ?

转载 作者:行者123 更新时间:2023-12-01 00:49:15 24 4
gpt4 key购买 nike

这好像是101级,但我找不到答案! (相反,我找到了成功或失败时要执行的操作、jQuery 的 ajax().success 等的链接。

我的预感是:

  • 成功:200 HTTP 返回代码
  • 失败:其他任何情况。

最佳答案

这并不是一个真正的 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

因此,基本上,如果 HTTP 响应代码在 200 到 299(含)或 304 之间,则为 success 回调,否则为 error 回调。

关于jquery - 什么是 Ajax 调用 : 'success' or 'failure' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8773276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com