DataTables警告:table id = example - 第1行第1列请求的未知参数“1”

时间:2017-01-08 11:01:37

标签: javascript ajax datatables

获取错误“DataTables警告:table id = example - 第1行第1列请求的未知参数'1'。有关此错误的详细信息,请在从ajax api调用加载数据时查看http://datatables.net/tn/4”从后端收到的json如下所示

import UIKit
import AVFoundation

class ViewController: UIViewController {
    var player:AVAudioPlayer = AVAudioPlayer()

    @IBAction func play(_ sender: AnyObject)
    {
        player.play()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        do
        {
            let audioPath = Bundle.main.path(forResource: "Ken", ofType: "mp3")
            try player = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
        }
        catch
        {
            //ERROR
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

正在填充表数据的HTML div标签的片段如下所示。

[{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]

下面是我正在做的ajax调用,并且成功函数试图从json填充数据

         <table id="example" class="display" align="center" vertical-align="middle"; cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Customer Name</th>
                <th>Product</th>
                <th>Perticulars</th>
                <th>Address of customer.</th>
                <th>Contact number</th>
            </tr>
        </thead>
        <tbody>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</tbody>
        <tfoot>
            <tr>
                <th>Customer Name</th>
                <th>Product</th>
                <th>Perticulars</th>
                <th>Address of customer.</th>
                <th>Contact number</th>
            </tr>
        </tfoot>
    </table>

2 个答案:

答案 0 :(得分:1)

您需要拥有包含对象数组的data对象。

{"data": [{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]}

正在运作 DEMO

答案 1 :(得分:0)

就我而言,我只是在代码和错误中更改了以下内容

  

DataTables警告:表id = bootstrap-data-table2-请求的第0行的未知参数'0'。有关此错误的更多信息,请参见http://datatables.net/tn/4

不见了:

发件人:

<tbody>
  @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
    {
      <tr>
        @if (item.Approved == "1")
        {
        <td>@item.Date</td>
        <td>@item.Date</td>
        <td>@item.Type</td>
        <td>@item.Amount</td>
        }
      </tr>
    }
</tbody>

收件人:

<tbody>
  @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
    {
    if (item.Approved == "1")
      {
      <tr>
        <td>@item.Date</td>
        <td>@item.Date</td>
        <td>@item.Type</td>
        <td>@item.Amount</td>
      </tr>
      }
    }
</tbody>