First I am not very good in JavaScript so maybe I do not know some very basics... I apologize in advance.
I created a form where I want to save every change in single fields directly without the need to submit the form each time. Therefore I created a custom route which returns an AjaxResponse on successfull database savings as well as on any errors on the Drupal side.
But I want to be aware of any errors which may appear on the client side as well. $.ajax()
has the function .fail()
and .done()
where I can do different things in my JavaScript when something went wrong. These methods are missing for Drupal.ajax()
. Is there any way to react on errors when using Drupal.ajax()
?
I tried
try {
Drupal.ajax({url: path}).execute();
}
catch (e) {
alert(e.name + ": " + e.message);
}
and built in some errors on my controller but all that happens is that the browsers console lists Ajax errors - no alert is shown to the client.