数据表中的 sAjaxSource 返回错误 [英] sAjaxSource in datatable returns error

查看:23
本文介绍了数据表中的 sAjaxSource 返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误警报 =DataTables 警告(表 id = 'msnc_table'):从第 0 行的数据源请求未知参数 '1'"

I keep on receiving this error alert = "DataTables warning (table id = 'msnc_table'): Requested unknown parameter '1' from the data source for row 0"

这是我的代码片段:

HTML:

  <table id="msnc_table" class="dataTable">
  <thead>
    <tr>
        <th>Doc#</th>
        <th>Date</th>
        <th>Code</th>
        <th>Customer Name</th>
        <th>S/m</th>
        <th>Gross</th>
        <th>Disc</th>
        <th>Net</th>
        <th>S.Disct</th>
        <th>Invc</th>
    </tr>
 </thead>
 <tbody>
     <tr>
         <td class="dataTables_empty">Loading data from server</td>
     </tr>
 </tbody>
 </table>

JS

var msnc_table = $('#msnc_table').dataTable({
   "bProcessing": true,
   "bServerSide": true,
   "iDisplayStart": 0,
   "iDisplayLength": 11,
   "sAjaxSource": base_url+"raw/raw_ajax/get_mnsc",
   "bRetrieve": true
});

PHP 函数

function get_mnsc()
{
   echo '{"sEcho":"2","iTotalRecords":20,"iTotalDisplayRecords":20,"aaData":   [["232412","12/8/2012","DSDA2312","Alfonso supermarket","213","231213","21312","2313","2313","2312432
"],["232412","12/8/2012","ADS332","MCL Store","213","231213","21312","2313","2313","2312432
"]]}'
}

推荐答案

Datatables.net 的此类错误通常意味着您指定的标题/列与从服务器返回的 JSON 之间存在不匹配.

但是,在您的情况下,JSON 的每一行"中似乎正确地有 10 个和 10 个项目.

However, in your case there seem to correctly be 10 ths and 10 items in each 'row' of JSON.

这让我认为 JSON 格式不正确,或者 DataTables 无法处理其中的某些部分.

This makes me think that the JSON is incorrectly formatted, or that DataTables can't process some part of it.

我建议你打开fiddler检查响应,因为它实际上在客户端,我对php了解不多,因此不确定该回声将如何实际出现在客户端上.但当然认为你应该编码和设置标题,例如

I'd suggest you whip open fiddler and inspect the response as it actually is on client, I don't know much php, so not certain how that echo will actually appear on the client. But certainly think you should encode and set the headers e.g.

从 PHP 脚本返回 JSON

您可以将该提琴手的输出复制到 http://jsonformatter.curiousconcept.com/http://jsonlint.com/来验证它.

You can copy that fiddler output to http://jsonformatter.curiousconcept.com/ or http://jsonlint.com/ to validate it.

这可能是你的日期,在斜线前有什么看起来像转义字符的东西?,把它搞砸了.注意我的日期被返回,例如

It may be your dates, with what look like escape characters before the slashes?, are messing it up. N.B. my dates are returned e.g.

"31/07/2005",

可能是 JSON 中看起来错误的换行符把它搞砸了?

It may be that the line breaks which look to be in wrong place in your JSON are messing it up?

"2312432
"] 

建议您将它们完全删除并查看它是否有效,或者在引号之后或方括号关闭之后放置中断?

Suggest you remove them entirely and see if it works, or place the break after the quotes, or after the square bracket closes?

"2312432"
]

"2312432"]
 

不确定,但肯定会根据链接修改 php,如果仍有问题,请使用 fiddler 检查实际响应.

Not sure, but certainly mod the php as per link, and use fiddler to inspect actual response if you're still having problems.

如果仍有问题,请在此处查看答案.. 可能会有所帮助 https://stackoverflow.com/a/11475749/661584

If you still have issues, then check the answer here.. may help https://stackoverflow.com/a/11475749/661584

祝你好运!值得让 Datatables.net 工作 - 太棒了!

Good Luck ! Worth it to get Datatables.net working - its great !

这篇关于数据表中的 sAjaxSource 返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆