开发者

jquery xhr success and error states

开发者 https://www.devze.com 2023-03-16 10:44 出处:网络
What are all the xhr states that jquery accepts as success states? Similarly what are the error states? I know 200 is a success state and 401 is an error state. 开发者_如何学JAVAAny further informatio

What are all the xhr states that jquery accepts as success states? Similarly what are the error states? I know 200 is a success state and 401 is an error state. 开发者_如何学JAVAAny further information on this could be helpful. Can someone please point me to a good read. I could not get the information from jquery api.


When I can't find an answer in the docs, I dive into the source. Here's the bit you're looking for, specifically line 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;
        }
    }
}


http://docs.jquery.com/Ajax_Events this will be a help


I just googled,

how about this

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

0

精彩评论

暂无评论...
验证码 换一张
取 消