W
W
WillieShibelgut2021-03-29 16:13:42
AJAX
WillieShibelgut, 2021-03-29 16:13:42

How to implement loader during form submit via AJAX?

Hello! Can you please tell me how to implement a spinner or loader while the form submission is being processed? There is now a jQuery script that hides the form and shows a thank you box on successful submission:

$('form').submit(function(e) {
    e.preventDefault();
    $.ajax({
        type: "POST",
        url: "mailer/smart.php",
        data: $(this).serialize()
    }).done(function() {
        $(this).find("input").val("");
        $('.callback, .fancybox-bg, .service-popup').fadeOut('fast');
        $('#thanks').fadeIn('slow');
        setTimeout(function() {
          $('#thanks').fadeOut('slow');
        },2000);
        $('form').trigger('reset');
    });
    return false;
});


Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vovash, 2021-03-29
@V0vash

jQuery.ajax({
    type: "POST",
    url: 'YOU_URL_TO_WHICH_DATA_SEND',
    data:'YOUR_DATA_TO_SEND',
    beforeSend: function() {
        $("#loader").show();
    },
    success: function(data) {
        $("#loader").hide();
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question