0

HTML ファイルと同じディレクトリにある feature-table.JSON は次のとおりです。

[
  {
    "band": "Weezer",
    "song": "El Scorcho"
  },
  {
    "band": "Chevelle",
    "song": "Family System"
  }
]

これが私のHTMLファイルです:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.11.1.min.js">
<script type="text/javascript" src="jquery.dynatable.js"></script>
<script type="text/javascript">
$.getJSON("feature-table.JSON", function(data) {
    alert(data);
    $("#feature-table").dynatable({
        dataset: {
            records: data
        }
    });
});
</script>
</head>
<body>
<table id="feature-table">
  <thead>
    <th>band</th>
    <th>song</th>
  </thead>
  <tbody>
  </tbody>
</table>
</body>
</html>

正しい JSON データを含むアラートがポップアップ表示されるので、それが見つかっていることがわかります。私は試しました:jQueryのバージョン2、jsファイルのURLをアップロードして使用して、ファイルが正しい場所にあることを確認します. 私はアイデアがありません。私は何を見落としていますか?

4

2 に答える 2

2

JavaScript を に含める必要があることを発見し$(document).ready(function(){...})ました。

于 2014-06-16T22:56:18.563 に答える
0

お役に立てれば。

JSON 配列のドキュメントに従って、メタデータも含めましたか。

    {
      "records": [
        {
          "someAttribute": "I am record one",
          "someOtherAttribute": "Fetched by AJAX"
        },
        {
          "someAttribute": "I am record two",
          "someOtherAttribute": "Cuz it's awesome"
        },
        {
          "someAttribute": "I am record three",
          "someOtherAttribute": "Yup, still AJAX"
        }
      ],
      "queryRecordCount": 3,
      "totalRecordCount": 3
    }
于 2014-06-18T13:43:48.527 に答える