我试图用来自服务器的值来填充数据表,我不使用数据表的ajax函数,因为我也在页面的其他部分使用这些值。我已经使用过这种类型的fullfill但我不明白为什么在这种情况下没有任何事情发生,表格仍然是空的。我试图检查值是否存在和是,所以配置中可能存在错误......但是什么? 这是我的代码:
var datas = [];
$.ajax({
url: getServer(FN_SERVER),
success: function(resp) {
for(var i=0;i<resp.data.length;i++) {
campaigns[resp.data[i].id] = resp.data[i];
var elem = []
elem.push(resp.data[i].id);
elem.push(resp.data[i].desc.trim());
elem.push(resp.data[i].ccode.trim());
elem.push(resp.data[i].scode.trim());
elem.push(resp.data[i].ecode.trim());
datas.push(elem);
}
}
});
var cols = [
{"title":"id"},
{"title":"desc"},
{"title":"ccode"},
{"title":"scode"},
{"title":"ecode"},
{ "render": function(data, type, row) {
return "<input type='image' title='Info' src='"+getContextPath()+"/images/info.png' onclick='campagne.showInfo(this)'>";
},
"orderable": false,
"class":"align_center"
},
{ "render": function(data, type, row) {
return "<input type='image' title='Conf' src='"+getContextPath()+"/images/settings.png' onclick='campagne.showUpdateCamp(this)'>";
},
"orderable": false,
"class":"align_center"
}
];
var table = $("#table").dataTable({
"scrollY": "300px",
"scrollX": true,
"bSort": false,
"orderMulti": false,
"searching": false,
"paging": false,
"bInfo": false,
"columns": cols,
"data": datas,
"language": {
"emptyTable": NORECORD,
"zeroRecords": NORECORD
},
"drawCallback": function() {
}
});