doucuoyan0426 2010-11-19 02:48
浏览 25

即使echo与DataTables匹配,JSON格式也会出错

I run a lengthy PHP script I was modifying to PDO formatting as opposed to crappy mysql Db calls. At the end of the script, the $output is json encoded with:

echo json_encode( $output );

When I run the two scripts, the output to screen is IDENTICAL but my jquery DataTables program returns an error on the PDO encoded results and not the mysql return.

I have run regex's on the two results and they are IDENTICAL so why this is happening is beyond me.

Anybody ever had the same issue?

EDIT

DataTables error states:

DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.

  • 写回答

5条回答 默认 最新

  • dtt83024 2010-11-19 07:33
    关注

    One method to use is to grab the JSON return from Firebug (or Webkit's inspector or whatever) and run it through http://jsonlint.com . If the JSON string is identical, then I would guess that there is something else being output (perhaps a PHP warning, or just an echo of a string somewhere) which is causing the parsing to fail. DataTables makes use of the JSON parser built into jQuery 1.4, and will give this error when the parser cannot decode the string.

    If that doesn't help, are you able to give us a link to the page?

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法