Good evening. There is a form and js, I can not understand why .serializeArray () does not work. In the console, displays [] (the topics raised here are re-read, experimented, but nothing helped).

<form class="form-horizontal" id="objectInfo"> <div class="form-group"> <label for="name" class="col-sm-2 control-label">Наименование*</label> <div class="col-sm-10"> <input type="text" class="form-control" id="name" required value="Все пользователи"> </div> </div> <div class="form-group"> <label for="active" class="col-sm-2 control-label">Состояние*</label> <div class="col-sm-10"> <input type="text" class="form-control" id="active" required value="True"> </div> </div> <div class="col-sm-10" style="text-align: center;"> <button type="submit" id="submitObjectButton" class="btn btn-primary objectButton">Сохранить</button> </div> </form> <script> $(document).ready(function(){ // submit button $('#objectInfo').submit(function (e) { var result = { }; var arr = $('#objectInfo').serializeArray(); console.log(arr); $.each($('#objectInfo').serializeArray(), function() { console.log(this.name); console.log(this.value); result[this.name] = this.value; }); e.preventDefault(); }); }); </script> 

    2 answers 2

    serializeArray () do not apply to each control separately, but to the whole form

    • I did just that, a typo (experimental results) ... - Ildus N.
    • Give an example of a working code in order to show the performance of your version - Vasily Barbashev
    • This is the "working code" (non-working), several inputs have been removed since there are too many of them. Or lay out the whole "footwoman"? I can only assume that the reason is that this form is received / added to the site by ajax request ... maybe this is the case ?! - Ildus N.

    Found the reason, it turned out you need to add a name for the input fields, for example,

      <input type="text" class="form-control" name="active" id="active" required value="True"> 

    Thanks to all )