Ajax Form submit options

  • 4 December 2019
  • 1 reply
  • 24 views

Hello,

I apologize if this has been asked and answered already but I couldn’t find specifics.

I need to add/change some ajax parameters in my form submit callback function. I have this:

function yourSubmitFunction(e, $) {
    e.preventDefault();
    //CUSTOM CODE HERE
    $.post( 'my-submit-url', $('form').serialize() );
    $('.lp-pom-form form').submit();
  }
  $('form').ready(function($) {
    $('.lp-pom-form .lp-pom-button').unbind('click').bind('click.formSubmit', function(e) {
      if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
    });
    $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
      if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
        yourSubmitFunction(e, $);
    });
  });

==============================================

This works, but I am getting CORS errors submitting to Pardot (our marketing automation platform)

The way I’ve gotten this to work on our website is by adding {dataType: 'jsonp', crossDomain: true} inside of the ajaxForm plugins ajaxSubmit() function:

$(form).ajaxSubmit({dataType: 'jsonp', crossDomain: true});

I tried adding that to my above $('.lp-pom-form form').submit(); (which seems to be ajax) and it does submit and work in Pardot, but my Unbounce page acts as if it never submits and doesn’t bring up the form submit conformation window.

I assume that might be because I have overridden the ajax parameters with no callback?


1 reply

One obvious question is if .submit() is the same as none ajax submit (like it would normally) be or if you can add parameters. It seems by inspection that this is type : “ajax” so it must be a custom function. Is there any way to change it’s output?

Reply