diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fa3dd35e78eb0cfa308e35c3b0821756216d589b..d311993f85db33dbfc09a53463c91273b3a374d2 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,9 @@ Drupal 7.51, xxxx-xx-xx (development version) - Log messages are now XSS filtered on display. - Draggable tables do now work on touch screen devices. - Added setting for allowing double underscores in CSS identifiers. +- If a user navigates away from a page while an AJAX request is running they + will no longer get an error message saying "An AJAX HTTP request terminated + abnormally" - Numerous performance improvements. - Numerous small bugfixes. - Numerous API documentation improvements. diff --git a/misc/ajax.js b/misc/ajax.js index bb4a6e14f9962a48bb0a2670638d840751fc0fe2..c944ebbf246193da3c9fc209e58b72d240f61ff9 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -476,7 +476,7 @@ Drupal.ajax.prototype.getEffect = function (response) { * Handler for the form redirection error. */ Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { - alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); + Drupal.displayAjaxError(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); // Remove the progress element. if (this.progress.element) { $(this.progress.element).remove(); diff --git a/misc/autocomplete.js b/misc/autocomplete.js index d71441b6c73df1a0b538278a9f4a2c57f4a27765..af090713c730f095881c7040947cc064232296e4 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -310,7 +310,7 @@ Drupal.ACDB.prototype.search = function (searchString) { } }, error: function (xmlhttp) { - alert(Drupal.ajaxError(xmlhttp, db.uri)); + Drupal.displayAjaxError(Drupal.ajaxError(xmlhttp, db.uri)); } }); }, this.delay); diff --git a/misc/drupal.js b/misc/drupal.js index 427c4a1e29ea648788083c219678712ed76226dc..03eef50edc943201278ef1c086055714297b02cd 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -413,6 +413,29 @@ Drupal.getSelection = function (element) { return { 'start': element.selectionStart, 'end': element.selectionEnd }; }; +/** + * Add a global variable which determines if the window is being unloaded. + * + * This is primarily used by Drupal.displayAjaxError(). + */ +Drupal.beforeUnloadCalled = false; +$(window).bind('beforeunload pagehide', function () { + Drupal.beforeUnloadCalled = true; +}); + +/** + * Displays a JavaScript error from an Ajax response when appropriate to do so. + */ +Drupal.displayAjaxError = function (message) { + // Skip displaying the message if the user deliberately aborted (for example, + // by reloading the page or navigating to a different page) while the Ajax + // request was still ongoing. See, for example, the discussion at + // http://stackoverflow.com/questions/699941/handle-ajax-error-when-a-user-clicks-refresh. + if (!Drupal.beforeUnloadCalled) { + alert(message); + } +}; + /** * Build an error message from an Ajax response. */