I'm using Webix UI modal, this is how i use it:
this.add = function () {
scrollArea.css("overflow", "hidden");
$.ajax({
type: "GET",
url: "/detail/create",
success: function (form) {
webix.message.keyboard = false;
webix.modalbox({
title: "New detail",
buttons: ["Accept", "Decline"],
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 () {
}
});
}
};
And form's HTML:
<form action="" id="detail_add" method="post">
<input type="text" name="name" placeholder="Name">
<input type="text" name="article" placeholder="Article">
<input type="hidden" name="location_id" placeholder="1">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</form>
When i click Accept in modal, my JSON is empty. How can i fix it? I was trying to get input's value by console.log, but it's empty too.
It's not an answer in general but the example code is not applicable to resolve something because:
Here is the code slightly changed to work and to demonstrate your case:
I'm using Webix UI modal, this is how i use it:
scrollArea = $(window.document);
this.add = function() {
//scrollArea.css("overflow", "hidden");
$.ajax({
type: "GET",
url: "/detail/create",
beforeSend: function(form) {
webix.message.keyboard = false;
webix.modalbox({
title: "New detail",
buttons: ["Accept", "Decline"],
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() {}
});
}
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://cdn.webix.com/edge/webix.css" type="text/css">
<script src="http://cdn.webix.com/edge/webix.js" type="text/javascript"></script>
<form action="" id="detail_add" method="post">
<input type="text" name="name" placeholder="Name">
<input type="text" name="article" placeholder="Article">
<input type="hidden" name="location_id" placeholder="1">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<button onClick="add()">Add</button>
</form>
When i click Accept in modal, my JSON is empty. How can i fix it? I was trying to get input's value by console.log, but it's empty too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With