There is a form that should be sent without rebooting, for this I use this jquery code:
$(document).ready(function(){ $.ajaxSetup({ headers: {"X-CSRF-Token": "{{csrfToken}}" } }); $('#edit-profile_form').submit(function(e) { e.preventDefault(); var data = $("form").serialize(); console.log(data); $.ajax({ contentType:"text/plain; charset:UTF-8", global: false, async: true, type: 'POST', url: '/user/changeProfileData', dataType: 'text', data: data, success: function (result) { console.log(result); }, error: function (request, status, error) { console.log(error); } }); console.log("Send to server!"); }); }); When preventDefault is in the code, {} is an empty object on the server. And if it is not there, then the page reloads (which is bad), but all the necessary data comes to the server (which is good). How to deal with it? Here is the form itself:
<form action="/user/changeProfileData" id="edit-profile_form" method="post"> <ul class='profile-data'> <li class='profile-data_item persona-icon'>ΠΠΈΠΊΠ½Π΅ΠΉΠΌ: <input id='profile_nickname' name='nickname' type="text" placeholder="ΠΠΈΠΊΠ½Π΅ΠΉΠΌ:" value="{{myNickname}}" ></li> <li class='profile-data_item'>ΠΠΌΡ: <input name='name' id='profile_name' type="text" placeholder="ΠΠΌΡ:" value="{{myName}}" ></li> <li class='profile-data_item'>Π€Π°ΠΌΠΈΠ»ΠΈΡ: <input name='surname' id='profile_surname' type="text" placeholder="Π€Π°ΠΌΠΈΠ»ΠΈΡ:" value="{{mySurname}}" ></li> <li class='profile-data_item b-day-icon'>ΠΠΎΠ·ΡΠ°ΡΡ: <input name='age' id='profile_age' type="text" placeholder="ΠΠΎΠ·ΡΠ°ΡΡ:" value="{{myAge}}" ></li> <li class='profile-data_item place-icon'><input type="text" name='city' id='profile_city' placeholder="ΠΠΎΡΠΎΠ΄" value="{{myCity}}" >, <input name='country' id='profile_country' type="text" placeholder="Π‘ΡΡΠ°Π½Π°" value="{{myCountry}}" ></li> <li class='profile-data_item phone-icon'>Π’Π΅Π»Π΅ΡΠΎΠ½: <input name='phoneNumber' id='profile_phoneNumber' type="text" placeholder="Π’Π΅Π»Π΅ΡΠΎΠ½:" value="{{myPhoneNumber}}" ></li> <input type="hidden" name="_csrf" value='{{csrfToken}}' /> <input type="submit" value="Submit" id="edit-profile_submit"> </ul> </form>
$("form").serialize()return$("form").serialize()? - Grundy