Hello, help me understand the code, I have not studied anywhere js and so on.

$(document).ready(function(){ //Проверка корректности введенных данных function validateData(){ var errors = new Array(); if( $('input[name="email"]').val() == '' ){ errors.push( 'Поле "Эл. почта" не может быть пустым' ); } if( $('input[name="password-first"]' ).val() == '' ){ errors.push( 'Поле "Пароль" не может быть пустым' ); } if( $('input[name="password-second"]').val() == '' ){ errors.push( 'Поле "Подветржение пароля" не может быть пустым' ); } if( $('input[name="password-second"]').val() != $('input[name="password-first"]' ).val() ){ errors.push( '"Пароль" и "Подветржение пароля" должны совпадать' ); } if( $('input[name="name"]').val() == '' ){ errors.push( 'Поле "Имя" не может быть пустым' ); } if( errors.length > 0 ){ var message = "Внимание:\n"; message += errors.join("\n"); alert( message ); return false; } return true; } /** * Отправка формы при нажатии кнопки "Зарегестрировать" */ $('#register').click(function(){ if( validateData() ){ $('#employer-registration').submit(); dataLayer.push({'registration_employer': 'registration_employer_success'}); } }); }); 

such is the code. I need to do so that when successful! data level of the datalayer transmitted to the server as well datalayer

 dataLayer.push({'registration_employer': 'registration_employer_success'}); 

I apologize for the stupid questions. HELP Thank.

  • Curve some question turned out. The essence of the question is, did I set the data level correctly? Please tell me the code: $ ('# register') what does jQuery mean? Is it a link to another file? - Alexander Mishura
  • This is the element selector with id='register' . Read about selectors in jQuery - yolosora
  • I haven't studied anywhere js and so on - maybe it’s worth starting if you want to write code on it? and many questions will disappear immediately ... - Alex
  • > I have not studied anywhere js and so on - then you should first study it, and then ask questions - ThisMan
  • Thank you very much for the answers, read, I realized what was about. Guys, I don’t code, I have another job, I just needed to figure it out. - Alexander Mishura

1 answer 1

This is most likely you need to write not in this section of the code that you sent. And where you collect data from the fields and send it with the POST method. There you need to put your dataLayer array.

In your case, the code that sends something to the server should look something like this (or at least contain such a request):

 $.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType }); 

The data parameter contains an array or an object, or JSON, or just a string that sends data from the fields.

You need either to attach your dataLayer to this line, or write a similar request and send the dataLayer separately.

  • Thanks !!! - Alexander Mishura
  • A counter question arose whether there was by chance some kind of simple Chrome extension in order to search for such files that send data. - Alexander Mishura
  • @Alexander Mishura, you just need to write console.log (here your variables or something else that you send to the server) and you will see everything in the developer’s tools in the browser. - Roman Tatarinov
  • @Alexander Mishura and if you need a beautiful display of JSON in the browser, then here’s the extension: chrome.google.com/webstore/detail/json-formatter/… - Roman Tatarinov
  • @Alexander Mishura If you want to check the submission or something like that, you can use this: chrome.google.com/webstore/detail/postman/… - Roman Tatarinov