【发布时间】:2018-01-11 23:01:51
【问题描述】:
我正在使用DataTables 并想在其中显示我的城市数据,但我没有做到。
例如,如果我打电话给this URL,那么我会以 JSON 格式获取城市数据(来自 openweathers map api)。我想简单地在我的数据表上显示这些数据。 请帮忙。
我的代码:
$.ajax({
type: "POST",
url: "http://api.openweathermap.org/data/2.5/group?id=2643741,2644688,2633352,2654675,2988507,2990969,2911298,2925535,2950159,3120501,3128760,5128581,4140963,4930956,5106834,5391959,5368361,5809844,4099974,4440906&appid=de6d52c2ebb7b1398526329875a49c57&units=metric",
dataType: "json",
success: function (result, status, xhr) {
$('#weatherTable').DataTable({
data: JSON.stringify(result),
columns: [
{ data: 'id' },
{ data: 'name' }
],
"pageLength": 3
});
},
error: function (xhr, status, error) {
console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
}
});
我只是得到错误:
DataTables 警告:表 id=weatherTable - 请求未知 第 0 行第 0 列的参数“id”。有关此的更多信息 错误,请看http://datatables.net/tn/4
请帮忙?
【问题讨论】:
-
为什么在尝试将数据插入表之前对其进行字符串化?
-
@Falk 我在没有搅拌的情况下尝试了它,但它仍然没有用。
标签: javascript jquery datatables