Why swears on formNm.serialize ()

<script> btnSubmit.onclick = function(){ var formID = 'price_form'; var formNm = $('#' + formID); $.ajax({ type: "POST", url: 'assets/ajax.php', data: { formNm.serialize(), action:'payments_user', }, success: function (data) { $('#message').html(data); setTimeout(function(){ $('#message').html(' '); },5000); location.reload(); }, error: function () { $('#message').html('Ошибка'); setTimeout(function(){ $('#message').html(' '); },5000); } }); return false; }; </script> 
  • "swears" - what words? - Igor
  • Unexpected token. - Aslero

1 answer 1

You missed the field name in the object for the data property:

 data: { values: formNm.serialize(), action:'payments_user', }, 

A more correct way:

 btnSubmit.onclick = function(){ var formID = 'price_form'; var formNm = $('#' + formID); if (formNm.find("#action").length == 0) { formNm.append("<input type='hidden' name='action' id='action' />"); } formNm.find("#action").val("payments_user"); $.ajax({ type: "POST", url: 'assets/ajax.php', data: formNm.serialize(), success: function (data) { ... 
  • now transfers empty values ​​to the file - Aslero
  • @Aslero in what "file"? Do you think I can see the thoughts in your brain? - Igor
  • assets / ajax.php - Aslero
  • echo $ _POST ['id_user']; gives empty value - Aslero
  • one
    @Aslero you would do well to think about accepting answers to your questions. 120 questions one accepted answer - it should be a record. - Igor