【问题标题】:jquery xhr success and error statesjquery xhr 成功和错误状态
【发布时间】:2011-07-01 14:08:57
【问题描述】:

jquery 接受作为成功状态的所有 xhr 状态是什么?同样,错误状态是什么?我知道 200 是成功状态,而 401 是错误状态。有关这方面的任何进一步信息可能会有所帮助。有人可以指点我阅读。我无法从 jquery api 获取信息。

【问题讨论】:

    标签: jquery xmlhttprequest


    【解决方案1】:

    当我在the docs 中找不到答案时,我会跳入the source。这是您要查找的内容,特别是第 2 行:

    // 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;
    
        // If we have data
        } else {
    
            try {
                success = ajaxConvert( s, response );
                statusText = "success";
                isSuccess = true;
            } catch(e) {
                // We have a parsererror
                statusText = "parsererror";
                error = e;
            }
        }
    } else {
        // We extract error from statusText
        // then normalize statusText and status for non-aborts
        error = statusText;
        if( !statusText || status ) {
            statusText = "error";
            if ( status < 0 ) {
                status = 0;
            }
        }
    }
    

    【讨论】:

    • 感谢凯文的回复。这有帮助。你能推荐任何关于这个主题的一般读物吗?
    • 我想不出任何我读过的东西可以澄清这一点,但谷歌搜索可能会证明我错了。不过,消息来源很能说明问题。
    【解决方案2】:

    http://docs.jquery.com/Ajax_Events这将是一个帮助

    【讨论】:

    • 我在那里找不到问题的答案
    【解决方案3】:

    我刚刚用谷歌搜索过,

    这个怎么样

    http://www.w3.org/TR/XMLHttpRequest/

    【讨论】:

    • 除了不回答问题花钱——太棒了!
    • @Quentin,抱歉我没有查看完整的细节,看起来那是一些课程,我删除了它并从 w3.org 提供了一些信息。
    • 这也不能回答问题——“jQuery 认为哪些状态是成功的?”
    猜你喜欢
    • 2015-05-04
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多