[英]Requested unknown parameter, when Showing Data in DataTable
I am using this reference .我正在使用这个参考。 I have a Form when I submit my form It will add row in datatable with inputted data.
我提交表单时有一个表单,它将在数据表中添加带有输入数据的行。 but when I submitting button it showing [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] instead of data.
但是当我提交按钮时,它显示[object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object]而不是数据。
Here is my Html Code:这是我的 Html 代码:
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Add Item For Requisition</h4>
</div>
<div class="modal-body">
<div class="form-group row">
<div class="col-md-2 input-sm">
<label class="pull-right">Item</label>
</div>
<div class="col-md-8 input-sm">
<input ID="txtSrchItem" type="text" class="form-control" placeholder="Item Code"/>
</div>
<div class="col-md-2 input-sm">
<button id="btnItemSrch" class="btn btn-info pull-right">Search</button>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 input-sm">
<label class="pull-right">Item Name</label>
</div>
<div class="col-md-10 input-sm">
<select class="form-control input-sm" id="ItemName">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 input-sm">
<label class="pull-right">Specification</label>
</div>
<div class="col-md-10 input-sm">
<input ID="txtItemSpecific" type="text" class="form-control" placeholder="Item Specification"/>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 input-sm">
<label class="pull-right">Unit</label>
</div>
<div class="col-md-4 input-sm">
<input ID="txtUnit" type="text" class="form-control" placeholder="Unit"/>
</div>
<div class="col-md-2 input-sm">
<label class="pull-right">Qnty</label>
</div>
<div class="col-md-4 input-sm">
<input ID="txtQty"type="text" class="form-control" placeholder="Qty"/>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 input-sm">
<label class="pull-right">Rate</label>
</div>
<div class="col-md-4 input-sm">
<input ID="txtrate" type="text" class="form-control" placeholder="Rate"/>
</div>
<div class="col-md-2 input-sm">
<label class="pull-right">Amount</label>
</div>
<div class="col-md-4 input-sm">
<input ID="txtamt" type="text" class="form-control" placeholder="Amount"/>
</div>
</div>
<div class="form-group row">
<label ID="lblMsg" class="form-control"></label>
</div>
</div>
<div class="modal-footer">
<button type="button" id="AddTable" class="btn btn-primary pull-left">Save changes</button>
<button type="button" class="btn btn-danger " data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
Ajax Handling for accepting the request:用于接受请求的 Ajax 处理:
$(document).ready(function () {
var t = $('#example').DataTable();
var counter = 1;
$('#AddTable').on('click', function () {
var txtSrchItem = $('#txtSrchItem').val();
var ItemName = $('#ItemName').val();
var txtItemSpecific = $('#txtItemSpecific').val();
var txtUnit = $('#txtUnit').val();
var txtQty = $('#txtQty').val();
var txtrate = $('#txtrate').val();
var txtamt = $('#txtamt').val();
$.ajax({
data: {
'txtSrchItem' : txtSrchItem,
'ItemName' : ItemName,
'txtItemSpecific' : txtItemSpecific,
'txtUnit' : txtUnit,
'txtQty' : txtQty,
'txtrate' : txtrate,
'txtamt' : txtamt
},
success: function (data) {
t.row.add([
{ 'data' : 'txtSrchItem' },
{ 'data' : 'ItemName' },
{ 'data' : 'txtItemSpecific' },
{ 'data' : 'txtUnit' },
{ 'data' : 'txtQty' },
{ 'data' : 'txtrate' },
{ 'data' : 'txtamt' }
]).draw(false);
}
});
counter++;
});
// Automatically add a first row of data
//$('#AddTable').click();
});
Unless you define in column definitions to look for object properties for each column, the plugin expects an array of primitive values for each row by default.除非您在列定义中定义以查找每一列的对象属性,否则默认情况下插件需要每一行的原始值数组。
Look at the columns
definitions in the reference link in your question查看您问题中参考链接中的
columns
定义
Or try basic values array:或尝试基本值数组:
success : function(data){
var rowData = [txtSrchItem, ItemName, ... , txtamt];
t.row.add(rowData).draw(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.