File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -339,11 +339,7 @@ function pjax(options) {
339
339
}
340
340
341
341
// Cancel the current request if we're already pjaxing
342
- var xhr = pjax . xhr
343
- if ( xhr && xhr . readyState < 4 ) {
344
- xhr . onreadystatechange = $ . noop
345
- xhr . abort ( )
346
- }
342
+ abortXHR ( pjax . xhr )
347
343
348
344
pjax . options = options
349
345
var xhr = pjax . xhr = $ . ajax ( options )
@@ -409,12 +405,8 @@ if ('state' in window.history) {
409
405
// stuff yet.
410
406
function onPjaxPopstate ( event ) {
411
407
412
- // Cancel the current request if we're already pjaxing
413
- var xhr = pjax . xhr
414
- if ( xhr && xhr . readyState < 4 ) {
415
- xhr . onreadystatechange = $ . noop
416
- xhr . abort ( )
417
- }
408
+ // hitting back or forward should override any pending PJAX request
409
+ abortXHR ( pjax . xhr ) ;
418
410
419
411
var state = event . state
420
412
@@ -518,6 +510,16 @@ function fallbackPjax(options) {
518
510
form . submit ( )
519
511
}
520
512
513
+
514
+ // Internal: Abort an XmlHttpRequest if it hasn't been completed,
515
+ // also removing its event handlers.
516
+ function abortXHR ( xhr ) {
517
+ if ( xhr && xhr . readyState < 4 ) {
518
+ xhr . onreadystatechange = $ . noop
519
+ xhr . abort ( )
520
+ }
521
+ }
522
+
521
523
// Internal: Generate unique id for state object.
522
524
//
523
525
// Use a timestamp instead of a counter since ids should still be
You can’t perform that action at this time.
0 commit comments