dsa88886666 2010-06-10 01:07
浏览 106
已采纳

jQuery DataTables:POST Server Side JSON输出的问题

I am trying to get my datatable to take a POST JSON output from my server.

This is my client side code:

<script>
$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "http://localhost/staff/jobs/my_jobs",
        "fnServerData": function ( sSource, aoData, fnCallback ) {
            $.ajax( {
                "dataType": 'json', 
                "type": "POST", 
                "url": sSource, 
                "data": aoData, 
                "success": fnCallback
            } );
        }
    } );
} );
</script>

Now I have copied and pasted the server side code found in the DataTables examples found here.

When I change my sAjaxSource to view this page the table doesn't move beyond 'processing'.

When I view the JSON directly I see this output.

{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","First Ever Job"]] }

Just for fun I went to the POST server-side example and copied some of the JSON they are using for their example and just PHP echoed it straight out of another page.

This is the output of that page.

{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","Internet Explorer 4.0"]] }

Here is where it gets interesting.

The JSON that has been processed by the server fails to work yet the JSON simply echo'd by the same server on a different page does work... yet both are identical in outputs.

I hope someone can shed some light on this because as the tree said to the lumberjack... I'm stumped.

Thanks,

Tim

  • 写回答

1条回答 默认 最新

  • doujia7779 2010-06-10 22:59
    关注

    I just found out how to view the POST variables with firebug. This showed an error from the server saying that fnColumnToField function was undefined. I checked the server side script and found it at the bottom. I moved the function to the top.

    Suddenly the table was working.

    This seems strange because i literally copied and pasted the code from the examples on http://www.datatables.net.

    Whats even stranger is that when i viewed the page directly it was also showing correct validated JSON output...

    Perhaps it has something to do with me integrating this into codeigniter. Either way it is working now and I am a very happy man.

    Thankyou Tim

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示