Ticket #3442: jsonabort.patch
| File jsonabort.patch, 3.4 KB (added by morgan, 5 years ago) |
|---|
-
jquery/src/ajax.js
175 175 s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s)); 176 176 177 177 var jsonp, jsre = /=\?(&|$)/g, status, data, 178 type = s.type.toUpperCase(); 178 type = s.type.toUpperCase(), 179 requestDone = false; 179 180 180 181 // convert data if not already a string 181 182 if ( s.data && s.processData && typeof s.data != "string" ) … … 206 207 207 208 // Handle JSONP-style loading 208 209 window[ jsonp ] = function(tmp){ 209 data = tmp; 210 success(); 211 complete(); 210 requestDone = true; 211 212 if(!window[ jsonp ].aborted) 213 { 214 data = tmp; 215 success(); 216 complete(); 217 } 212 218 // Garbage collect 213 219 window[ jsonp ] = undefined; 214 220 try{ delete window[ jsonp ]; } catch(e){} 215 221 if ( head ) 216 222 head.removeChild( script ); 217 223 }; 224 225 window[ jsonp ].aborted = false; 226 window[ jsonp ].abort = function() { this.aborted = true; } 218 227 } 219 228 220 229 if ( s.dataType == "script" && s.cache == null ) … … 262 271 script.onload = script.onreadystatechange = function(){ 263 272 if ( !done && (!this.readyState || 264 273 this.readyState == "loaded" || this.readyState == "complete") ) { 265 done = true; 266 success(); 267 complete(); 274 275 requestDone = done = true; 276 277 if(!script.aborted) 278 { 279 success(); 280 complete(); 281 } 282 268 283 head.removeChild( script ); 269 284 } 270 285 }; 286 287 script.aborted = false; 288 script.abort = function() { this.aborted = true; }; 271 289 } 272 290 273 291 head.appendChild(script); 274 292 275 293 // We handle everything using the script element injection 294 if(s.timeout > 0) 295 setTimeout(function() 296 { 297 if(requestDone) 298 return; 299 300 if(jsonp) 301 window[ jsonp ].abort(); 302 else 303 script.abort(); 304 305 if(s.error) 306 s.error("timeout"); 307 }, s.timeout); 308 309 // We handle everything using the script element injection 310 if(jsonp) 311 return window[ jsonp ]; 312 if(script) 313 return script; 276 314 return undefined; 277 315 } 278 316 279 var requestDone = false;280 281 317 // Create the request object 282 318 var xhr = s.xhr(); 283 319
