I have a webform that sends an email upon submission. Ajax is enabled so when I hit submit and there are errors on the form they will show instantly. However if there are no errors I would like to hide the form along with the success message.

Some pseudo code (sort of):

Drupal.behaviors.sendMail = {
  attach: function (context) {

    $('#webform-client-form-340', context).ajaxComplete(function(event, xhr, settings) {
      if ($('.alert-errors').length == 1) {
      } else {


This doesn't work because the .alert-errors div is not yet there on ajaxComplete. So how do I check for errors, highlight the form if they are present and otherwise hide the form?

  • So I got a hack to work at least. If there are errors the xhr response will be valid json otherwise not so I'm doing a try and catch on $.parseJSON(xhr.responseText) and hide the form if the json doesn't parse.
    – schwifty
    Commented Jun 24, 2013 at 19:07

1 Answer 1


I when I normally have to debug this I use

Debugging ajax with FIREPHP

Explaines how you can debug ajax with FIREPHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.