1

I'm posting a form to admin-ajax and the redirect use to be within the success handler. That was taking too long to receive from the server then redirect, even though it was only a small json response giving a success message. I've since moved the redirect to execute after the .ajax() call. Is there any chance the redirect could execute before the AJAX posted? I know AJAX is asynchronous so it's executing in the background.

    jQuery.ajax({
      type:"POST",
      url:admin_ajaxurl,
      dataType: "Json",
      data: {
        action: "lp_contact",
        post: postData
      },
      beforeSend: function(jqXHR, data, setting){

      },
      success: function(data){          

      },
      error: function(data) {
      }

    }); // End update prospect
    window.location.replace("http://www.example.com/thank-you-landing-page/");
    return false;

1 Answer 1

2

The problem could be in using admin ajax. If you switch to a different endpoint, the process may speed up.

I've used ajax flow on a few sites and you should see a performance gain: https://wordpress.org/support/view/plugin-reviews/ajaxflow

Check out some best practices here:
https://10up.github.io/Engineering-Best-Practices/php/#libraries

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.