简体   繁体   English

在 DataTable 中显示数据时请求未知参数

[英]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">&times;</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();
           });

Here is the image of error这是错误的图像
物品信息

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.

相关问题 添加数据时的Jquery Datatable警告:请求的未知参数 - Jquery Datatable warning when adding data: Requested unknown parameter 请求jQuery数据表中的第0行的未知参数1 - requested unknown parameter 1 for row 0 in jquery datatable 数据表显示:DataTables 警告:表 id=userdetails - 为第 0 行、第 1 列请求未知参数“1” - Datatable showing :DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, column 1 绑定的jQuery数据表给出错误“来自数据源的第0行的请求的未知参数&#39;0&#39;” - binding jquery datatable gives error “Requested unknown parameter '0' from the data source for row 0” 数据表警告:表 id=DimStatus - 初始化数据表时,第 0 行第 0 列请求未知参数“代码” - DataTables warning: table id=DimStatus - Requested unknown parameter 'Code' for row 0, column 0,when initialize datatable 数据表错误:第0行第10列请求的未知参数&#39;10&#39;; 尝试将复选框添加到数据表时 - Datatables error: Requested unknown parameter '10' for row 0, column 10; when tried to add checkbox to the datatable 从数据源请求行“ 0”的未知参数“ 1” - Requested unknown parameter '1' from the data source for row '0' 请求第1行的未知参数“ 0” - Requested unknown parameter '0' for row 1 DataTables - 请求的未知参数 - DataTables - Requested unknown parameter 从数据源请求的行0问题的未知参数&#39;0&#39; - Requested unknown parameter '0' from the data source for row 0 issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM