mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Detect AJAX abort due to page unload #1280
This commit is contained in:
parent
766cd4b1d5
commit
953faecd55
1 changed files with 29 additions and 0 deletions
|
|
@ -15,6 +15,11 @@
|
|||
*/
|
||||
window.show_leaving_warning = false;
|
||||
|
||||
/**
|
||||
* This variable becomes true when the user tries to navigate away from the page.
|
||||
*/
|
||||
var page_unloading = false;
|
||||
|
||||
/**
|
||||
* This variable stores the .wfsr jQuery object.
|
||||
*/
|
||||
|
|
@ -127,6 +132,11 @@
|
|||
return xmlHandler(xhr, textStatus);
|
||||
}
|
||||
|
||||
// If the user is navigating away, don't do anything.
|
||||
if (xhr.status == 0 && page_unloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the waiting message and display an error notice.
|
||||
clearTimeout(wfsr_timeout);
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
|
|
@ -266,6 +276,13 @@
|
|||
|
||||
// Define the error handler.
|
||||
var errorHandler = function(xhr, textStatus) {
|
||||
|
||||
// If the user is navigating away, don't do anything.
|
||||
if (xhr.status == 0 && page_unloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the waiting message and display an error notice.
|
||||
clearTimeout(wfsr_timeout);
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
var error_info;
|
||||
|
|
@ -338,6 +355,13 @@
|
|||
|
||||
// Define the error handler.
|
||||
var errorHandler = function(xhr, textStatus) {
|
||||
|
||||
// If the user is navigating away, don't do anything.
|
||||
if (xhr.status == 0 && page_unloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the waiting message and display an error notice.
|
||||
clearTimeout(wfsr_timeout);
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
var error_info = xhr.status + " " + xhr.statusText + " (" + textStatus + ")";
|
||||
|
|
@ -423,6 +447,7 @@
|
|||
* Empty placeholder for beforeUnload handler.
|
||||
*/
|
||||
var beforeUnloadHandler = function() {
|
||||
page_unloading = true;
|
||||
return "";
|
||||
};
|
||||
|
||||
|
|
@ -438,6 +463,10 @@
|
|||
}).bind("ajaxStop cancel_confirm", function() {
|
||||
$(window).unbind("beforeunload", beforeUnloadHandler);
|
||||
});
|
||||
} else {
|
||||
$(window).on('beforeunload', function() {
|
||||
page_unloading = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue