sAjaxSource在datatable中返回错误 [英] sAjaxSource in datatable returns error

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

问题描述

我继续收到此错误alert =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\r\n"],["232412","12\/8\/2012","ADS332","MCL Store","213","231213","21312","2313","2313","2312432\r\n"]]}'
}


推荐答案

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格式不正确,或者数据表无法处理某些部分它。

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.

这可能是你的日期,在斜杠之前看起来像转义字符? N.B.我的日期返回,例如

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\r\n"] 

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

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

"2312432"\r\n]

"2312432"]\r\n 

不确定,但肯定会根据链接修改php,并使用提示者检查实际响应如果你还有问题

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

如果您仍然遇到问题,请在此处查看答案。可能有助于 http://stackoverflow.com/a/11475749/661584

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

祝你好运!值得让Datatables.net工作 - 它的伟大!

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

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

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