doufu5747 2013-05-20 20:04
浏览 148

jQuery dataTables没有加载AJAX JSON数据

I have a table that is populated via dataTables with information from a MySQL table. The information is prepared via PHP as proper JSON in the way dataTables expects the information.

The problem I'm having is the table no longer loads informations. Even reverting my changes so that the JSON data does not include links to the server description (via view.php) doesn't change anything.

The site can be found here: checkersthecat.com/status The PHP that outputs JSON information can be found here: checkersthecat.com/status/inc/json-servers.php

Here is the code for json-servers.php

<?php

$db = new PDO("mysql:host=localhost;dbname=mcstatus;charset=UTF8", "user", "pass");

$stmt = $db->prepare("SELECT ip, port, category, players, tries, description FROM clients");
$stmt->execute();
$servers = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = $stmt->rowCount();

$data = array(
    "aaData" => array()
);

foreach ($servers as $item) {
    $arr = array();

    // Address
    if (strlen($item['description']) == 0) {
        if ($item['port'] != 25565) {
            array_push($arr, $item['ip'] . ":" . $item['port']);
        } else {
            array_push($arr, $item['ip']);
        }
    } else {
        if ($item['port'] != 25565) {
            array_push($arr, "<a href='inc/view.php?ip=" . $item['ip'] . "'>" . $item['ip'] . ":" . $item['port'] . "</a>");
        } else {
            array_push($arr, "<a href='inc/view.php?ip=" . $item['ip'] . "'>" . $item['ip'] . "</a>");
        }
    }

    // Category
    array_push($arr, $item['category']);

    // Status
    if ($item['tries'] == 0) {
        array_push($arr, "Up");
    } else {
        array_push($arr, "Down (" . $item['tries'] . ")");
    }

    // Players
    if ($item['players'] == -1) {
        array_push($arr, "?");
    } else {
        array_push($arr, $item['players']);
    }

    array_push($data['aaData'], $arr);
}

header("Content-type: application/json");
echo json_encode($data);

?>

The snippet of javascript that actually initializes and sets up the dataTable is here:

// init load of table
serverTable = $("#servers").dataTable({
    "bProcessing": true,
    "bStateSave": true,
    "sPaginationType": "two_button",
    "sAjaxSource": "http://checkersthecat.com/status/inc/json-servers.php"
});

It literally worked, I changed one small item relating to the description length in the javascript relating to a jQuery modal dialog form, I refreshed the page, and suddenly dataTables no longer loads my JSON information.

I'm at a total loss as to why it will not work. Even reverting to my old code without the hyperlinks in the JSON data and previous description limits doesn't make a difference. It still gives me an endless "Processing" and "Loading". When I try to search it merely says "No data available" which is ludicrous as the JSON information is right there at the URL and is valid.

I've tried debugging the javascript and PHP with firebug and turning on error reporting respectively, but apparently there isn't anything wrong with it all as far as I know.

Any help is very appreciated as this has had me tearing my hair out. If there's any other details that you may need, please let me know.

  • 写回答

1条回答 默认 最新

  • dongzongpeng6474 2013-05-21 15:17
    关注

    It works, but I'm unsure what exactly the problem was.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?