使用数据表简单加载数据

时间:2015-01-12 02:46:15

标签: jquery jquery-datatables

我正在尝试使用数据表加载数据,但是当我运行此页面时,显示processing不会出现任何错误。

<html>

<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="../../html/content/css/app.css">
  <script src="../../html/content/js/library/jquery.js"></script>
  <script>
    $(document).ready(function() {
      $('#data').dataTable({
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "http://api.geonames.org/countryInfoJSON?username=design1online",
        "sPaginationType": "full_numbers"
      });
    });
  </script>
</head>

<body>
  <div>
    <div class="widget-gridview">
      <table cellpadding="0" cellspacing="0" border="0" id="data" width="100%">
        <thead>
          <tr>
            <th style="width:6em"> continent</th>
            <th> capital</th>
            <th style="width:6em"> languages</th>
            <th style="width:4em"> population</th>
          </tr>
        </thead>
        <tbody>
          <tr class="odd">
            <td width="140"> </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
        </tbody>
        <tfoot></tfoot>
      </table>
    </div>
  </div>
</body>

</html>

2 个答案:

答案 0 :(得分:0)

enter image description here建议:

  1. 包括dataTable js和css文件
  2. 从调试控制台,出现错误消息&#34; Uncaught TypeError:无法读取属性&#39;长度&#39;未定义&#34;
  3. 每条记录中有17个属性,但您的html代码中每行只有4个td。
  4. 这是您的一条数据记录。

    &#34;大陆&#34;:&#34; EU&#34 ;, &#34;资本&#34;:&#34; Andorra la Vella&#34;, &#34;语言&#34;:&#34; CA&#34 ;, &#34; geonameId&#34;:3041565, &#34;南&#34;:42.42849259876837, &#34; isoAlpha3&#34;:&#34;与&#34 ;, &#34;北&#34;:42.65604389629997, &#34; fipsCode&#34;:&#34; AN&#34 ;, &#34;人口&#34;:&#34; 84000&#34 ;, &#34;东&#34;:1.7865427778319827, &#34; isoNumeric&#34;:&#34; 020&#34 ;, &#34; areaInSqKm&#34;:&#34; 468.0&#34 ;, &#34; COUNTRYCODE&#34;:&#34; AD&#34 ;, &#34;西&#34;:1.4071867141112762, &#34;国家名称&#34;:&#34;安道尔&#34 ;, &#34; continentName&#34;:&#34;欧洲&#34; &#34; CURRENCYCODE&#34;:&#34; EUR&#34;

答案 1 :(得分:0)

JSON无效:

Parse error on line 1212:
...: "EU",            "
----------------------^
Expecting 'STRING'