Bug Tracker

Ticket #1768: 1768.diff

File 1768.diff, 2.6 kB (added by davidserduke, 1 year ago)

patch (not complete)

  • src/ajax.js

     
    184184            // that a JSONP style response is executed properly 
    185185            s.dataType = "script"; 
    186186 
     187            function jsonpEnd() { 
     188                // Garbage collect 
     189                window[ jsonp ] = undefined; 
     190                try{ delete window[ jsonp ]; } catch(e){} 
     191            } 
     192 
    187193            // Handle JSONP-style loading 
    188194            window[ jsonp ] = function(tmp){ 
    189195                data = tmp; 
    190196                success(); 
    191197                complete(); 
    192                 // Garbage collect 
    193                 window[ jsonp ] = undefined; 
    194                 try{ delete window[ jsonp ]; } catch(e){} 
     198                jsonpEnd(); 
    195199            }; 
    196200        } 
    197201 
     
    221225        // If we're requesting a remote document 
    222226        // and trying to load JSON or Script with a GET 
    223227        if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) { 
    224             var head = document.getElementsByTagName("head")[0]; 
    225             var script = document.createElement("script"); 
     228            var head = document.getElementsByTagName("head")[0], 
     229                script = document.createElement("script"), 
     230                done = false; 
    226231            script.src = s.url; 
    227232 
    228             // Handle Script loading 
    229             if ( !jsonp ) { 
    230                 var done = false; 
    231  
    232                 // Attach handlers for all browsers 
    233                 script.onload = script.onreadystatechange = function(){ 
    234                     if ( !done && (!this.readyState ||  
    235                             this.readyState == "loaded" || this.readyState == "complete") ) { 
    236                         done = true; 
    237                         success(); 
     233            function scriptTagEnd(how) { 
     234                if (!done) { 
     235                    done = true; 
     236                    status = how; 
     237                    // don't do success/complete calls on jsonp success 
     238                    if (!jsonp || status != "success") { 
     239                        if (status == "success") 
     240                            success(); 
     241                        else { 
     242                            jQuery.handleError(s, null, status); 
     243                            if (jsonp) 
     244                                jsonpEnd(); 
     245                        } 
    238246                        complete(); 
    239                         head.removeChild( script ); 
    240247                    } 
    241                 }; 
     248 
     249                    head.removeChild( script ); 
     250                } 
    242251            } 
    243252 
     253            // Attach handlers for all browsers 
     254            script.onload = script.onreadystatechange = function(){ 
     255                if ( !done && (!this.readyState ||  
     256                        this.readyState == "loaded" || this.readyState == "complete") ) 
     257                    // opera sets the .text value so we can test that, the other browsers don't so have assume success 
     258                    scriptTagEnd(this.text || !jQuery.browser.opera ? "success" : "error"); 
     259            }; 
     260            script.onerror = function(){ 
     261                scriptTagEnd("error"); 
     262            }; 
     263 
     264            if (s.timeout) 
     265                setTimeout(function(){ scriptTagEnd("timeout"); }, s.timeout); 
     266 
    244267            head.appendChild(script); 
    245268 
    246269            // We handle everything using the script element injection