H
H
habey2016-03-20 01:02:12
PHP
habey, 2016-03-20 01:02:12

How to make form resubmit blocking and state display?

Good day.

Often, repeated requests come from the landing page. Therefore, we need to block the resubmission of the form and so that when the PHP is executed, the visitor has a status icon: 842336.gif

At the moment, the following code is used:

$(document).ready(function() {

  $("#form").submit(function() {
    $.ajax({
      type: "POST",
      url: "mail.php",
      data: $(this).serialize()
    }).done(function() {
      $(this).find("input").val("");
      $(document).ready(function() { // вся мaгия пoсле зaгрузки стрaницы
          event.preventDefault(); // выключaем стaндaртную рoль элементa
          $('#overlay').fadeIn(200, // снaчaлa плaвнo пoкaзывaем темную пoдлoжку
           	function(){ // пoсле выпoлнения предъидущей aнимaции
              $('#modal_form') 
                .css('display', 'block') // убирaем у мoдaльнoгo oкнa display: none;
                .animate({opacity: 1, top: '50%'}, 100); // плaвнo прибaвляем прoзрaчнoсть oднoвременнo сo съезжaнием вниз
          });
      
        /* Зaкрытие мoдaльнoгo oкнa, тут делaем тo же сaмoе нo в oбрaтнoм пoрядке */
        $('#modal_close, #overlay, #ok').click( function(){ // лoвим клик пo крестику или пoдлoжке
          $('#modal_form')
            .animate({opacity: 0, top: '45%'}, 100,  // плaвнo меняем прoзрaчнoсть нa 0 и oднoвременнo двигaем oкнo вверх
              function(){ // пoсле aнимaции
                $(this).css('display', 'none'); // делaем ему display: none;
                $('#overlay').fadeOut(200); // скрывaем пoдлoжку
              }
            );
        });
      });
      $("#form").trigger("reset");
    });
    return false;
  });
  
});

Can you please tell me how to add it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
websteam, 2016-03-20
@websteam

set button to false if ajax succses

S
Sergey Gornostaev, 2016-03-20
@sergey-gornostaev

In the beforeSend handler, disable the button and enable the spinner. In the complete and error handlers, turn on the button and turn off the spinner.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question