Using Custom Ajax Scripts with Vae Forms
  • Has anyone used a custom ajax script in-place of the ajax feature provided by Vae?

    I am wondering if writing a custom ajax request using jQuery would provide a bit more control over the logic for errors, success, etc.

  • 6 Answers sorted by
  • I'd imagine this would be a little difficult. Our server is really only designed to handle responses from our AJAX calls, and doesn't return any generic JSON objects or anything like that that you could deal with.

    You're free to try it though!

  • What specifically are you trying to do?

  • Hey Mike.

    Well, I am familiar with using the built-in ajax attribute for Vae forms. It all works fine that way, but I have never really liked that you have to set the redirect attribute to a another file for the confirmation display. On a site where you might have multiple forms, I feel like it gets a little cluttered to have a bunch of confirmation page files.

    Another thing I like to do is hide or disable the submit button after it is clicked (and show a loading indicator). This gets a bit awkward to handle if there is an error from the server. e.g. Using the Vae newsletter signup tag, you get a server-side error if your email is already signed up on the list.

    So I have been trying to hook into ajaxComplete and ajaxStart events to deal with the situations, and for the most part it has worked. It still gets a little buggy at times and in IE8. e.g. I have had a hard time getting my submit button show again if an error is returned.

    Any ideas would be welcome. Thanks Mike.

  • I would just use the HTML markup that is generated with those verb tags, and have it submit into some status DIV. Then the redirect results would show up in the div, the form would still stay visible.

  • $('form').submit(function(){
    var url = $(this).attr('action');
    var data = $(this).serialize();

    $.post(url,function(data){

    $('.result').html(data);

    });

    /* stop form from submitting normally */
    event.preventDefault();

    });

  • Good stuff Mike. I'll give that a shot. Thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion