There is a more or less standard form that is tested with Ajax. The problem is that it starts working only from the second time, after reloading the page. Another difficulty is that the code is not mine and I’m not good at figuring out what the problem is.
Link to the form itself: https://www.advantika.ru/test.php
Javascript:
$('.form form').submit(function(e) { if(!! window.FormData){ e.preventDefault(); $form = $(this); $submitButton = $form.find('[name="web_form_submit"]'); $submitButton.addClass('proceed').prop('disabled', true); var formData = new FormData(this); formData.append('web_form_submit', $submitButton.val()); $.ajax( { url: 'https://www.advantika.ru/_formHandler.php', type: 'POST', data: formData, processData: false, contentType: false, cache: false, success: function(response){ $response = $(response); if($response.find('.form-form-note').length > 0){ if('order' == $form.attr('name')){ var checkedServices = []; $form .find('.form-services') .find('[type=checkbox]') .each(function(){ if(true === $(this).is( ':checked' )){ checkedServices.push($(this).attr('data-gtm-val')); } }); var gtmEventLabel = document.URL + '|' + checkedServices.join('.') + '|'; }else{ var gtmEventLabel = document.URL; } dataLayer.push({ 'event': 'adv.event', 'eventCategory': 'formSubmit', 'eventAction': $form.attr('name'), 'eventLabel': gtmEventLabel, 'eventValue': 0, 'eventNonInteraction': false }); $form.find('.form-element input').val(''); $form.find('.form-element textarea').val(''); $form.find('input[type=checkbox]').prop('checked', false); } $form.find('.form-messages').stop().html($response.find('.form-messages').stop().html()); $submitButton.prop('disabled', false).removeClass('proceed'); } }); return false; }else{ $(this).submit(); } });
$('.form form').submit(function(){})to$(document).on('submit','.form form',function(){ ... } )- xAqweRx