jQuery .load的回调函数中textStatus参数的所有可能值是什么? [英] What are all of the possible values of the textStatus parameter in the callback function of jQuery .load?
问题描述
我正在使用jQuery的 .load 方法的回调函数来运行某些代码,如果<.load
方法的c0>参数等于某个字符串.
I am utilising the callback function of jQuery's .load method to run certain code if the textStatus
parameter of the .load
method is equal to a certain string.
例如我有
jQuery("#myContainer").load('/seperate-file-with-content.asp', function(responseText, textStatus, xhr){
if (textStatus === "error" || responseText.length <= 0) {
//file failed to load i.e. textStatus == error
//or file loaded but has no content
} else {
//file loaded successfully i.e. textStatus == success
}
});
但是我担心if
语句的else
部分可能会捕获其他非预期的textStatus
值,这些值不等于success
.
But i'm worried that the else
part of the if
statement may catch other non expected textStatus
values that aren't equal to success
.
除了error
和success
之外,textStatus是否还有其他可能的值?
Are there any other possible values to textStatus, other than error
and success
?
编辑/更新::由于我现在认为.load
是基于.ajax
的,因此以下问题中的答案可能对具有类似问题的其他任何人都有用:-在jQuery的ajax成功回调中,textStatus将曾经不是成功"吗?
EDIT/UPDATE: As I now believe that .load
is based on .ajax
, the answers in the following question may be of use for anyone else with a similar question:- In jQuery's ajax success callback, will textStatus ever not be "success"?
推荐答案
load()
基于 $ .ajax(),此方法的文档将可能的状态列出为:
load()
is based on $.ajax(), and the documentation for this method lists the possible statuses as:
-
abort
-
error
-
notmodified
-
parsererror
-
success
-
timeout
abort
error
notmodified
parsererror
success
timeout
这篇关于jQuery .load的回调函数中textStatus参数的所有可能值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!