我创建了两个DatePicker,名称分别为date,toto和一个搜索按钮,用于检索数据。 我要搜索从日期和日期中选择的记录,然后单击搜索按钮以从数据库中检索数据以在数据表上显示。但是我成功地通过console.log检查了来自数据库的数据,但是没有传递给datatable。我正在从这样的数据表中获取错误(DataTables警告:table id = tbl-projects-请求的未知参数'vendor_id'为第0行,第0列)
表格
--debug
表格
<div class="col-sm-6 col-md-3">
<div class="form-group">
<label for="" class="col-sm-2 control-label">From Date</label>
<input type="date" class="form-control" id="from_date" name="from_date" placeholder="From Date" required>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="form-group">
<label for="" class="col-sm-2 control-label">To Date</label>
<input type="date" class="form-control" id="to_date" name="to_date" placeholder="To Date" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class=" btn btn-info" id="save" onclick="get_all()">Search</button>
<button type="button" class="btn btn-warning" data-dismiss="modal" id="close">Close</button>
</div>
JQuery
<table id="tbl-projects" class="table table-striped table-bordered" cellspacing="0"
width="100%">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</table>
Php
<script>
function get_all() {
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();
$.ajax({
url:"all_purchase.php",
type: "POST",
data:{from_date:from_date, to_date:to_date},
success: function (data) {
console.log(data);
total = data.total
console.log(data.total);
$('#tbl-projects').dataTable({
"aaData": data
,
"scrollX": true,
"aoColumns": [
{"sTitle": "vendor_id", "mData": "vendor_id"},
{"sTitle": "date", "mData": "date"},
{"sTitle": "total", "mData": "total"},
{"sTitle": "pay", "mData": "pay"},
{"sTitle": "due", "mData": "due"},
{"sTitle": "payment_type", "mData": "payment_type"}
]
});
},
error: function (xhr) {
console.log('Request Status: ' + xhr.status );
console.log('Status Text: ' + xhr.statusText );
console.log(xhr.responseText);
var text = $($.parseHTML(xhr.responseText)).filter('.trace-message').text();
// console.log(text)
}
});
}
</script>