Hello, such a problem. There is a form, after sending which and receiving a response from the server, a window should pop up. the form works, but there is no window, what could be the reason?

... <input type="submit" name="submit" class="buton" id="buton"> </form> <div class="overlay js-overlay-thank-you"> <div class="popup js-thank-you"> <h2>Спасибо за заявку. Мы свяжемся с вами в ближайшее время!</h2> <div class="close-popup js-close-thank-you"></div> </div> </div> 

Popup Styles

 .overlay { position: absolute; height: 100vh; width: 100%; top: 0; left: 0; background-color: rgba(0,0,0,0.5); display: none; } .popup{ position: absolute; width: 300px; height: 180px; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); padding: 40px; background-color: #fff; } .close-popup{ position: absolute; top: 15px; right: 15px; width: 23px; height: 23px; cursor: pointer; } .close-popup:before { content: " "; background-color: #000; position: absolute; top: 11px; left: -4px; width: 31px; height: 3px; -webkit-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); } .close-popup:after { content: " "; background-color: #000; position: absolute; top: 11px; left: -4px; width: 31px; height: 3px; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } 

And the script

 $(document).ready(function() { $("#form").submit(function(e){ e.preventDefault(); if(document.getElementById('form').name.value == '' || document.getElementById('form').email.value == '' || document.getElementById('form').phone.value == ''){ valid = false; return valid; } $.ajax({ type: "POST", url: "mail.php", data: $(this).serialize(), success: function(data){ $(".overlay").fadeIn(); $(this).find("input").val(''); $("#form").trigger("reset"); }, error: function(jqXHR, exception) { console.log(jqXHR); console.log(exception); } }); return; }); }); //закрыть форму $(".close-popup").click(function() { $(".overlay").fadeOut(); }); $(document).mouseup(function (e) { var popup = $(".popup"); if (e.target!=popup[0]&&popup.has(e.target).length === 0){ $(".overlay").fadeOut(); } }); 
  • Accurately pop-up window should appear по отправлению , and not по получению ответа сервера ? - Dmytryk
  • Upon receipt of the answer - of course, I'm sorry, I did not say so) - Glechik
  • @YuriGalay, everything works, the window pops up: jsbin.com/nuwazemiqe/edit?js,output (I just formatted the code a bit, I didn’t change anything). Check the mail.php script - it probably does not return an answer. - yar85
  • "form works" - ?? $(this).find("input").val(''); - what is this here? - Igor
  • @Igor Yes, the form works, but there is no pop-up window. You can help me with this, my skills are minimal, I can not cope myself - Glechik

1 answer 1

So. This is not an answer.

Add lines to code as shown below.

Click in the browser F12. The Developer Tools window opens. There is a bookmark "Console". Run the code. What messages appeared in the console?

 console.log("sending ajax"); // добавить $.ajax({ type: "POST", url: "mail.php", data: $(this).serialize(), success: function(data){ console.log("success"); // добавить $(".overlay").fadeIn(); $(this).find("input").val(''); $("#form").trigger("reset"); }, error: function(jqXHR, exception) { console.log("error"); // добавить console.log(jqXHR); console.log(exception); } }); 
  • Failed to load resource: net :: ERR_BLOCKED_BY_CLIENT - Glechik
  • If via Denwer, then there are 2 such errors, and through test hosting, then there are 13 such errors - Glechik
  • sending ajax success; But I changed the script. - Glechik
  • but now nothing comes to the mail - Glechik