In some instances the variable Drupal.beforeUnloadCalled in drupal.js is not set when the user exists the page, this triggers the alert "An AJAX HTTP request terminated abnormally" if an AJAX request is currently being processed.

This is related to https://www.drupal.org/project/drupal/issues/1232416.

Specifically, in mobile Safari, there's a timing issue when submitting a form using autocomplete (note that this will only happen if the form submits while the autocomplete field is still fetching results). Wrapping the alert in a setTimeout call delays processing of the alert until the rest of the javascript has been processed and should prevent the alert on beforeunload/pagehide events.

Comments

hadsie created an issue. See original summary.

hadsie’s picture

Status: Active » Needs review
StatusFileSize
new718 bytes
hadsie’s picture

Title: Drupal AJAX alerts » Drupal AJAX alerts can be triggered when leaving a page.
indytechcook’s picture

StatusFileSize
new3.45 KB

I had issues using this patch. The time wasn't long enough. Here is an updated patch to change the timeout if the state is 0.

HyperD’s picture

StatusFileSize
new66.63 KB

On Chrome, FF, Edge: it works perfectly but

Once applied delay-ajax-alerts-3039666-5.patch, I got the following error on IE11

SCRIPT1006: Expected ')'
drupal.js (518,58)

From investigation it seems it is from the section here below

-Drupal.displayAjaxError = function (message) {
+Drupal.displayAjaxError = function (message, status_code = 0) {
// 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);
- }
+ // Use setTimout to delay execution and ensure that beforeunload has had a chance
+ // to be called.
+ var delay = status_code == 0 ? 3000 : 1;
+ setTimeout(function () {
+ if (!Drupal.beforeUnloadCalled) {
+ alert(message);
+ }
+ }, delay);
};

In attachment the screenshot of all the generated errors on IE11
No errors on any other browser

grigoriunicolae’s picture

Issue tags: -JavaScript +JavaScript
StatusFileSize
new3.55 KB

Added the IE hotfix based on the patch from #5

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.