K
K
Kirill2018-07-16 17:03:05
AJAX
Kirill, 2018-07-16 17:03:05

How to show modal window after form submit?

The fact is that the window does not have time to appear, since the page is reloaded immediately.
I'm scratching my head, how do I do this?

$(document).ready(function(){
    $("#form").submit(function() { //устанавливаем событие отправки для формы с id=form
            var form_data = $(this).serialize(); //собераем все данные из формы
            $.ajax({
            type: "POST", //Метод отправки
            url: "mail/mail.php", //путь до php фаила отправителя
            data: form_data,
            success: function(data) {
                   //код в этом блоке выполняется при успешной отправке сообщения
                    $('.pop-up pop-up-thanks').show('100');
               },
               error: function(){
               	alert('error')
               },
            });
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2018-07-16
@cloudz

need to override the default action when submitting the form
e.preventDefault();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question