Home > database >  How to execute code only after the submission is done?
How to execute code only after the submission is done?

Time:06-26

  1. I have some code from a service called webflow where the form is controlled by them. I write the html form, but the form submission code is handled by a third party not me
  2. I need to run some code (trigger a redirect) after their submission is done.

Here is my attempt

$('#email-form').submit(function (event) {      
    window.location.href = url;
});

It works in some browser, but not in safari. Apparently, this breaks this original form submission code.

My second attempt, this works

    $('#email-form').submit(function (event) {      
    setTimeout(function(){
    window.location.href = url;
    }, 500);

});

By giving it some time, the submission code fires first, then my code runs and successfully redirects.

What is a more robust way of writing this code (not reliant on some random timer wait)?

CodePudding user response:

I think the best way to work this in every browser is

  • Related