I have a form element that triggers an AJAX callback call when it looses focus. This callback can take a few seconds, which generally is not an issue.
If a user submits the form before the AJAX callback completes, the following error is displayed:
Here is the exact error message displayed to the end user:
An AJAX HTTP request terminated abnormally.Debugging information follows.Path: /system/ajaxStatusText: ResponseText: ReadyState: 4
How can I gracefully terminate an AJAX callback from completing when passing control to a submit handler?
This is the relevant code from the module.
function a_custom_form($form, &$form_state) {
$form['email'] = array(
'#prefix' => '<div id="cust-email">',
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('Customer Email Address'),
'#required' => TRUE,
'#ajax' => array(
'callback' => '_user_email_ajax',
'wrapper' => 'cust-email',
'effect' => 'fade',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit Request'),
);
return $form;
}
function _user_email_ajax($form, &$form_state) {
$commands = array();
// Doing time intensive stuff here...
drupal_set_message(t('Some Message'), 'error');
$commands[] = ajax_command_replace('#email-warning-message', '<div id="email-warning-message">'. theme('status_messages') . '</div>');
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
I have tried the solution given for Prevent "AJAX HTTP request terminated" error on early form submit, but this seems to prevent the submit button from functioning, rather than interrupting the AJAX callback.