O
O
obraz462015-11-10 17:49:13
JavaScript
obraz46, 2015-11-10 17:49:13

Closing a pop-up registration form?

How to make the pop-up registration form close via JS after filling:

$("form").on("submit", function (e) {
  $(".form").submit(function() {
        $.ajax({
            type: "POST",
            url: "mail.php",
            data: $(this).serialize()
        }).done(function() {
            alert("Спасибо за заявку!");
            setTimeout(function() {
                $(".forms").trigger("reset");
            }, 1000);
        });
        return false;
    });

});

In my code it is written like this

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail, 2015-11-10
Chirskiy @chirskiy_mixail

$(".forms").trigger("reset");
// После закрываете форму
$('.form').hide() // Прячете
$('.form').remove() // Или вовсе удаляете

A
Andrey Dyrkov, 2015-11-10
@VIKINGVyksa

In this code, you will have a memory leak. You hang an event when another one has fired and do not remove it. In general, when the .done method has completed, $.ajax must be closed. By code, you simply inform the user that everything is fine, hide the form and nullify the values ​​in it

...
.done(function(data) {
            alert("Спасибо за заявку!");
           $("ваша форма, либо из замыкания берём").hide();//либо анимацию проиграйте .fadeout();
            setTimeout(function() {
                $(".forms").trigger("reset");//ресет можно сделать сразу после скрытия формы, таймеры не к чему
            }, 1000);
        });
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question