我正在尝试以html形式呈现jquery数据表。现在,出于某种奇怪的原因,我可以看到我可以从API接收数据,但是datatable中没有显示任何内容。有趣的是,当我在本地机器上运行时,同样的代码可以完美地工作。但是当我检查heroku日志中的错误时,我发现我得到了这个错误。 错误日志
(index):254 Uncaught TypeError: Cannot read property 'length' of undefined
at Object.success ((index):254)
at fire (jquery-1.12.4.js:3232)
at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362)
at done (jquery-1.12.4.js:9840)
at XMLHttpRequest.callback (jquery-1.12.4.js:10311)
但是在我的本地服务器上,一切都很正常。你知道吗
$(document).ready(function () {
//We have to get all users in the system
var jsonres=[]
var orgid = $('#orgid').val();
console.log('orgid',orgid)
$.ajax({
url: "/user/api/v1/userapi/",
type: "get",
success: function (json) {
console.log("json", json)
json = json.results;
for(var i=0;i<json.length;i++){
console.log('jsonnnn',json[i].orgid)
if(json[i].orgid==orgid){
jsonres.push(json[i])
}
}
console.log('jso',jsonres)
var data = jQuery.map(jsonres, function (el, i) {
/* if(el.title.length>20){
el.title = el.title.substring(0,10) + '..........';
}*/
return [[el.userid, el.firstname, el.lastname, el.mobilenumber, el.email, el.isactive]];
});
$('#demotbl').DataTable({
"searching": true,
"bLengthChange": false,
"order": [[3, "desc"]],
"aaData": data,
"bPaginate": true,
"aoColumns": [
{"sTitle": "userid"},
{"sTitle": "firstname"},
{"sTitle": "lastname"},
{"sTitle": "mobilenumber"},
{"sTitle": "email"},
{"sTitle": "isactive"},
]
})
}
})
})
[
{
"userid": "test_001123456",
"firstname": "Remy",
"lastname": "Das",
"email": "av20078@gmail.com",
"mobilenumber": "082929992",
"isactive": "yes",
"orgid": "test_001"
},
{
"userid": "test_0013456",
"firstname": "s",
"lastname": "sss",
"email": "ABC@gmail.com",
"mobilenumber": "786894651",
"isactive": "yes",
"orgid": "test_001"
}
]
用
"dataSrc": ""
你的问题就解决了。你知道吗问题是,当您使用服务器端ajax时,它希望数据变量名为jsonResponse,例如:
相关问题 更多 >
编程相关推荐