I have a rest controller that accepts json and writes it to the database. There is a form from which values ​​are read after a submission and sent to the controller's handler method via ajax , everything is read except for the radio button, what could be the matter? The request is not sent from my ui, I sent requests through postman and everything works fine. So, the error is not in the bek. Here is the script:

 <script> $('#form').submit(function () { sendAjaxForm(); $("#reset").click(); event.preventDefault(); }); function sendAjaxForm() { var DATA = { name: $("#name").val(), description: $("#description").val(), create_date: $("#create_date").val(), place_storage: $("#place_storage").val(), reserved: $("#reserved").val() //МОЖЕТ ТУТ ЧТО-ТО НЕ ТО НАПИСАЛ? }; $.ajax({ url: LIST_PRODUCTS + "/create", type: "POST", data: JSON.stringify(DATA), dataType: "json", contentType:"application/json; charset=utf-8", async: true, success: function (response) { table.append( "<tr>" + "<td>" + response.id + "</td>"+ "<td>" + response.name + "</td>"+ "<td>" + response.description + "</td>"+ "<td>" + response.create_date + "</td>"+ "<td>" + response.place_storage + "</td>"+ "<td>" + response.reserved + "</td>"+ "<td><a href='#deleted' data-id='" + response.id + "' class='delete'>удалить</a></td>" + "<td><a href='#edit' data-id='" + response.id + "' class='js-button-edit'>редактировать</a></td>" + "</tr>"); }, error: function (response) { alert("Exception in SEND") } }); } </script> 

And this form:

 <div class="overlay js-overlay-create"> <div class="popup js-popup-create" > <form id="form" action=""> <%--<div class="main">--%> <div class="field"> <label id="forName" for="name">Наименование товара</label> <input type="text" name="name" id="name" required placeholder="Введите имя"><br/> </div> <div class="field"> <label id="forDescription" for="description">Описание</label> <textarea style="resize: none" name="description" id="description" placeholder="Введите описание"></textarea><br/> </div> <div class="field"> <label id="forDate" for="create_date">Дата</label> <input type="date" name="create_date" id="create_date" required placeholder="Введите дату"><br/> </div> <div class="field"> <label id="forPlace_storage" for="place_storage">Номер ячейки</label> <input type="number" name="place_storage" id="place_storage" pattern="[^0\D]\d*" required placeholder="Введите номер ячейки"><br/> </div> <div class="field"> <label id="forReserved" for="no">Зарезервирован: </label> <input type="radio" name="reserved" id="yes" value="true">Да <input type="radio" name="reserved" id="no" value="false">Нет </div> </div> <br/> <button type="submit" id="btn" class="btn btn-success">Сохранить</button> <button type="reset" id="reset" class="btn btn-danger">Очистить поля</button> </form> <div class="close-popup js-close-create"></div> </div> </div> 
  • must be $("input[name='reserved']").val() - Jigius
  • @Jigius, wrote. Prior to that, I constantly took val() as false , and with such a record it always takes as true - Maks Ohotnikov

1 answer 1

 $("input[name='reserved']:checked").val() 
  • Yes it is. Thank. It seems that I tried it like this .. When you answer me, the errors go away by themselves: D - Maks Ohotnikov