我正在尝试从datatable发布表单数据并使用不同的javascript获取值但我没有得到值
问题是当我点击按钮时它没有获取数据。 如何从数据表中的表单输入中获取所有值?
这是我的数据表
<script type="text/javascript">
$(function() {
$('#not_issued').DataTable({
paging: false,
processing: true,
serverSide: true,
responsive: true,
ajax:
{
url: '{{ route('monthly_bill.arrayy', $bill_period_id) }}',
type: 'POST'
},
columns: [
{
data: 'DT_Row_Index',
name: 'DT_Row_Index'
},
{
data: 'bill_number',
render: function(data, type, full)
{
return data+'<input name="bill_number[]" type="hidden" value="'+data+'" />';
}
},
{
data: 'unit_number',
name: 'unit_number',
render: function(data, type, full)
{
var tenant = full.name;
return '<b>'+data+'</b></br><span class="text-muted text-xs">'+tenant+'</span>';
}
},
{
data: 'width',
render: function(data, type, full)
{
var num = data;
var width = parseFloat(num).toFixed(2);
return width+' m<sup>2</sup>';
},
searchable: false,
orderable: false
},
{
data: null,
render: function(data, type, full)
{
var service_charge = full.service_charge;
var number_string = service_charge.toString(),
sisa = number_string.length % 3,
rupiah = number_string.substr(0, sisa),
ribuan = number_string.substr(sisa).match(/\d{3}/g);
if (ribuan)
{
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
return rupiah;
},
searchable: false,
orderable: false
},
{
data: 'zinking_fund',
render: function(data)
{
// var zinking_fund = full.service_charge;
var number_string = data.toString(),
sisa = number_string.length % 3,
rupiah = number_string.substr(0, sisa),
ribuan = number_string.substr(sisa).match(/\d{3}/g);
if (ribuan)
{
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
return rupiah;
},
searchable: false,
orderable: false
},
{
data: 'meteran_akhir',
name: 'meteran_akhir',
render: function(data)
{
return '<input name="meteran_akhir[]" type="text" value="'+data+'" rules="numeric" num-format="2" class="form-control" />';
},
searchable: false,
orderable: false
},
{
data: 'meteran_akhir_air',
name: 'meteran_akhir_air',
render: function(data)
{
return '<input name="meteran_akhir_air[]" type="text" value="'+data+'" rules="numeric" num-format="2" class="form-control" />';
},
searchable: false,
orderable: false
}
]
});
});
</script>
这个javascript我用来通过按钮id="bill-publish"
$(document).ready(function() {
$("#bill-publish").click(function(e) {
var chunk = 100;
var count = 0;
var data = {
bill_number: [],
service_charge: [],
meteran_akhir_air: [],
// meteran_awal: [],
meteran_akhir: [],
};
$("#main-content").hide();
var loading = $("<div class='text-center'>")
.append($("#img-loading").clone())
.insertBefore("#main-content");
setTimeout(function() {
// Mass assignment
var row = $(".bill-row");
row.each(function(i) {
data.bill_number.push($("[name='bill_number[]']", this).val());
data.service_charge.push($("[name='service_charge[]']", this).inputmask('unmaskedvalue'));
// data.water_usage.push($("[name='water_usage[]']", this).inputmask('unmaskedvalue'));
data.meteran_akhir_air.push($("[name='meteran_akhir_air[]']", this).inputmask('unmaskedvalue'));
data.meteran_akhir.push($("[name='meteran_akhir[]']", this).inputmask('unmaskedvalue'));
count++;
// jumlah data masih di bawah chunk
if (count % chunk != 0 && count!=row.length)
return;
$.ajaxq("monthly_bill", {
url: window.location.href,
type: "POST",
data: data,
error: function(res) {
loading.hide();
$("#main-content").html(res.responseText).show();
fn.notif("Terjadi kesalahan saat menyimpan data");
$.ajaxq.abort("monthly_bill");
throw "Failed to submit data.";
},
})
data.bill_number = [];
data.service_charge = [];
data.water_usage = [];
data.meteran_akhir_air = [];
data.meteran_akhir = [];
});
$.ajaxq("monthly_bill", {
url: window.location.href,
type: "PUT",
success: function(res) {
window.location.href = window.location.href;
},
error: function(res) {
loading.hide();
$("#main-content").html(res.responseText).show();
fn.notif("Terjadi kesalahan saat menyimpan data");
}
})
}, 500);
e.preventDefault();
});
})