I use webix UI, JS code:

this.add = function () { scrollArea.css("overflow", "hidden"); $.ajax({ type: "GET", url: "/detail/create", success: function (form) { webix.message.keyboard = false; webix.modalbox({ title: "Новая деталь", buttons: ["ДОБАВИТЬ", "ОТМЕНА"], text: form, width: 400, callback: function (result) { switch (result) { case "0": addDetail(); break; case "1": break; } scrollArea.css("overflow", "auto"); } }); } }); function addDetail() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); $.ajax({ type: "POST", url: "/detail/store", data: $('#detail_add').serialize(), contentType: "JSON", processData: false, success: function () { } }); } }; 
 <form action="" id="detail_add" method="post"> <input type="text" name="name" placeholder="Название"> <input type="text" name="article" placeholder="Артикул"> <input type="hidden" name="location_id" placeholder="1"> <input type="hidden" name="_token" value="{{ csrf_token() }}"/> </form> 

When you click on the APPLY button, an empty JSON is sent. What can be wrong?

    1 answer 1

    Found the answer - you had to use

     switch (result) { case "0": addDetail; break; case "1": break; } 

    Instead

     switch (result) { case "0": addDetail(); break; case "1": break; } 

    Because thus, the function was called when the modal window was called.