There was a problem with the execution of the script after submitting the form, on the desktop version all type-top, but on the mobile version of the element

.after('<h1 class="fancy-success">Бпасибо Π·Π° заявку!</h1> <p class="fancy-success">с Π²Π°ΠΌΠΈ свяТутся Π² блиТайшСС врСмя</p>') 

inserted twice. What could be the snag? Here is the script :

 <script> $(function(){ $('#contact').submit(function(){ var errors = false; $(this).find('span').empty(); $(this).find('input, textarea').each(function(){ if( $.trim( $(this).val() ) == '' ) { errors = true; $(this).next().text( 'НС Π·Π°ΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΠΎΠ»Π΅ ' + $(this).prev().text() ); } }); if( !errors ){ var data = $('#contact').serialize(); $.ajax({ url: 'index.php', type: 'POST', data: data, beforeSend: function(){ $('#submit').next().text('ΠžΡ‚ΠΏΡ€Π°Π²Π»ΡΡŽ...'); }, success: function(res){ if( res == 1 ){ // $('#contact').find('input:not(#submit), textarea').val(''); $("#contact").hide('slow').after('<h1 class="fancy-success">Бпасибо Π·Π° заявку!</h1> <p class="fancy-success">с Π²Π°ΠΌΠΈ свяТутся Π² блиТайшСС врСмя</p>'); }else{ $('#submit').next().empty(); alert('Ошибка ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ'); } }, error: function(){ alert('Ошибка!'); } }); } return false; }); }); </script> 

    1 answer 1

    I bow that you have two times the success .
    Do console.log() and see how many times it runs (1).

    Maybe you on the element and onTap and onClick.

    Then I would have logged what is happening in index.php for the number of entries per one appeal (2).

    Temporarily, you can use this approach:

     $('#contact').submit(function(e) { var me = $(this); e.preventDefault(); if( me.data('requestRunning') ) return; me.data('requestRunning', true); $.ajax({ type: "POST", url: "index.php", data: data, success: function(msg){}, error: function(){}, complete: function() { me.data('requestRunning', false); } }); }); 

    In general, for the beginning, you need to know (1) and (2) ...
    Write in the comments.