Bug Tracker

Changeset 5614

Show
Ignore:
Timestamp:
05/15/08 21:03:31 (7 months ago)
Author:
aflesler
Message:

jqueryjquery ajax: closes #1289. Renamed 'xml' and 'r' to 'xhr'.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/ajax.js

    r5605 r5614  
    275275        // Create the request object; Microsoft failed to properly 
    276276        // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available 
    277         var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); 
     277        var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); 
    278278 
    279279        // Open the socket 
    280280        // Passing null username, generates a login popup on Opera (#2865) 
    281281        if( s.username ) 
    282             xml.open(type, s.url, s.async, s.username, s.password); 
     282            xhr.open(type, s.url, s.async, s.username, s.password); 
    283283        else 
    284             xml.open(type, s.url, s.async); 
     284            xhr.open(type, s.url, s.async); 
    285285 
    286286        // Need an extra try/catch for cross domain requests in Firefox 3 
     
    288288            // Set the correct header, if data is being sent 
    289289            if ( s.data ) 
    290                 xml.setRequestHeader("Content-Type", s.contentType); 
     290                xhr.setRequestHeader("Content-Type", s.contentType); 
    291291 
    292292            // Set the If-Modified-Since header, if ifModified mode. 
    293293            if ( s.ifModified ) 
    294                 xml.setRequestHeader("If-Modified-Since", 
     294                xhr.setRequestHeader("If-Modified-Since", 
    295295                    jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" ); 
    296296 
    297297            // Set header so the called script knows that it's an XMLHttpRequest 
    298             xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 
     298            xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 
    299299 
    300300            // Set the Accepts header for the server, depending on the dataType 
    301             xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ? 
     301            xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ? 
    302302                s.accepts[ s.dataType ] + ", */*" : 
    303303                s.accepts._default ); 
     
    305305 
    306306        // Allow custom headers/mimetypes 
    307         if ( s.beforeSend && s.beforeSend(xml, s) === false ) { 
     307        if ( s.beforeSend && s.beforeSend(xhr, s) === false ) { 
    308308            // cleanup active request counter 
    309309            s.global && jQuery.active--; 
    310310            // close opended socket 
    311             xml.abort(); 
     311            xhr.abort(); 
    312312            return false; 
    313313        } 
    314314 
    315315        if ( s.global ) 
    316             jQuery.event.trigger("ajaxSend", [xml, s]); 
     316            jQuery.event.trigger("ajaxSend", [xhr, s]); 
    317317 
    318318        // Wait for a response to come back 
    319319        var onreadystatechange = function(isTimeout){ 
    320320            // The transfer is complete and the data is available, or the request timed out 
    321             if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) { 
     321            if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) { 
    322322                requestDone = true; 
    323323 
     
    329329 
    330330                status = isTimeout == "timeout" && "timeout" || 
    331                     !jQuery.httpSuccess( xml ) && "error" || 
    332                     s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 
     331                    !jQuery.httpSuccess( xhr ) && "error" || 
     332                    s.ifModified && jQuery.httpNotModified( xhr, s.url ) && "notmodified" || 
    333333                    "success"; 
    334334 
     
    337337                    try { 
    338338                        // process the data (runs the xml through httpData regardless of callback) 
    339                         data = jQuery.httpData( xml, s.dataType ); 
     339                        data = jQuery.httpData( xhr, s.dataType ); 
    340340                    } catch(e) { 
    341341                        status = "parsererror"; 
     
    348348                    var modRes; 
    349349                    try { 
    350                         modRes = xml.getResponseHeader("Last-Modified"); 
     350                        modRes = xhr.getResponseHeader("Last-Modified"); 
    351351                    } catch(e) {} // swallow exception thrown by FF if header is not available 
    352352 
     
    358358                        success(); 
    359359                } else 
    360                     jQuery.handleError(s, xml, status); 
     360                    jQuery.handleError(s, xhr, status); 
    361361 
    362362                // Fire the complete handlers 
     
    365365                // Stop memory leaks 
    366366                if ( s.async ) 
    367                     xml = null; 
     367                    xhr = null; 
    368368            } 
    369369        }; 
     
    377377                setTimeout(function(){ 
    378378                    // Check to see if the request is still happening 
    379                     if ( xml ) { 
     379                    if ( xhr ) { 
    380380                        // Cancel the request 
    381                         xml.abort(); 
     381                        xhr.abort(); 
    382382 
    383383                        if( !requestDone ) 
     
    389389        // Send the data 
    390390        try { 
    391             xml.send(s.data); 
     391            xhr.send(s.data); 
    392392        } catch(e) { 
    393             jQuery.handleError(s, xml, null, e); 
     393            jQuery.handleError(s, xhr, null, e); 
    394394        } 
    395395 
     
    405405            // Fire the global callback 
    406406            if ( s.global ) 
    407                 jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 
     407                jQuery.event.trigger( "ajaxSuccess", [xhr, s] ); 
    408408        } 
    409409 
     
    411411            // Process result 
    412412            if ( s.complete ) 
    413                 s.complete(xml, status); 
     413                s.complete(xhr, status); 
    414414 
    415415            // The request was completed 
    416416            if ( s.global ) 
    417                 jQuery.event.trigger( "ajaxComplete", [xml, s] ); 
     417                jQuery.event.trigger( "ajaxComplete", [xhr, s] ); 
    418418 
    419419            // Handle the global AJAX counter 
     
    423423 
    424424        // return XMLHttpRequest to allow aborting the request etc. 
    425         return xml; 
    426     }, 
    427  
    428     handleError: function( s, xml, status, e ) { 
     425        return xhr; 
     426    }, 
     427 
     428    handleError: function( s, xhr, status, e ) { 
    429429        // If a local callback was specified, fire it 
    430         if ( s.error ) s.error( xml, status, e ); 
     430        if ( s.error ) s.error( xhr, status, e ); 
    431431 
    432432        // Fire the global callback 
    433433        if ( s.global ) 
    434             jQuery.event.trigger( "ajaxError", [xml, s, e] ); 
     434            jQuery.event.trigger( "ajaxError", [xhr, s, e] ); 
    435435    }, 
    436436 
     
    439439 
    440440    // Determines if an XMLHttpRequest was successful or not 
    441     httpSuccess: function( r ) { 
     441    httpSuccess: function( xhr ) { 
    442442        try { 
    443443            // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 
    444             return !r.status && location.protocol == "file:" || 
    445                 ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 || 
    446                 jQuery.browser.safari && r.status == undefined; 
     444            return !xhr.status && location.protocol == "file:" || 
     445                ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 || 
     446                jQuery.browser.safari && xhr.status == undefined; 
    447447        } catch(e){} 
    448448        return false; 
     
    450450 
    451451    // Determines if an XMLHttpRequest returns NotModified 
    452     httpNotModified: function( xml, url ) { 
     452    httpNotModified: function( xhr, url ) { 
    453453        try { 
    454             var xmlRes = xml.getResponseHeader("Last-Modified"); 
     454            var xhrRes = xhr.getResponseHeader("Last-Modified"); 
    455455 
    456456            // Firefox always returns 200. check Last-Modified date 
    457             return xml.status == 304 || xmlRes == jQuery.lastModified[url] || 
    458                 jQuery.browser.safari && xml.status == undefined; 
     457            return xhr.status == 304 || xhrRes == jQuery.lastModified[url] || 
     458                jQuery.browser.safari && xhr.status == undefined; 
    459459        } catch(e){} 
    460460        return false; 
    461461    }, 
    462462 
    463     httpData: function( r, type ) { 
    464         var ct = r.getResponseHeader("content-type"), 
     463    httpData: function( xhr, type ) { 
     464        var ct = xhr.getResponseHeader("content-type"), 
    465465            xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, 
    466             data = xml ? r.responseXML : r.responseText; 
     466            data = xml ? xhr.responseXML : xhr.responseText; 
    467467 
    468468        if ( xml && data.documentElement.tagName == "parsererror" )