Ticket #1768: 1768.diff
| File 1768.diff, 2.6 kB (added by davidserduke, 1 year ago) |
|---|
-
src/ajax.js
184 184 // that a JSONP style response is executed properly 185 185 s.dataType = "script"; 186 186 187 function jsonpEnd() { 188 // Garbage collect 189 window[ jsonp ] = undefined; 190 try{ delete window[ jsonp ]; } catch(e){} 191 } 192 187 193 // Handle JSONP-style loading 188 194 window[ jsonp ] = function(tmp){ 189 195 data = tmp; 190 196 success(); 191 197 complete(); 192 // Garbage collect 193 window[ jsonp ] = undefined; 194 try{ delete window[ jsonp ]; } catch(e){} 198 jsonpEnd(); 195 199 }; 196 200 } 197 201 … … 221 225 // If we're requesting a remote document 222 226 // and trying to load JSON or Script with a GET 223 227 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; 226 231 script.src = s.url; 227 232 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 } 238 246 complete(); 239 head.removeChild( script );240 247 } 241 }; 248 249 head.removeChild( script ); 250 } 242 251 } 243 252 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 244 267 head.appendChild(script); 245 268 246 269 // We handle everything using the script element injection
