jQuery .load的回调函数中textStatus参数的所有可能值是什么? [英] What are all of the possible values of the textStatus parameter in the callback function of jQuery .load?

查看:136
本文介绍了jQuery .load的回调函数中textStatus参数的所有可能值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.

除了errorsuccess之外,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆