0
我试图记录追加到我这正从返回JSON AJAX请求加载表,但如果我尝试使用output.length
它返回一个大数目而不是750条记录。这将导致for
环路为10000次,而不是750为什么会这样运行?JSON对象的长度,而不是返回大值的预期750个记录
$(document).ready(function() {
getData();
});
function getData() {
$.ajax({
data: {
action: 'getData'
},
url: "api/ajaxcall.php",
type: 'post',
async: false,
dataType: 'html',
success: function(output) {
console.log(output.length);
// buildTable(result);
}
});
}
function buildTable(output) {
for (var i = 0; i < output.length; i++) {
$('<tr>').append(
$('<td>').text(output[i].naam),
$('<td>').text(output[i].perc),
$($('<input id="' + output[i].id + '" onclick="editData(this)" type = "button" value = "Edit" />')),
$($('<input id="' + output[i].id + '" onclick="readData(this)" type = "button" value = "Read" />')),
$($('<input id="' + output[i].id + '" onclick="deleteRow(' + output[i].id + ')" type = "button" value = "Delete" />'))
).appendTo('#tableA');
}
}
你'dataType'不正确。长度可能是JSON _string_的长度。 – robertklep
*不要*使用'异步:FALSE'。这是非常糟糕的做法。你也应该看看在使用委派的事件处理程序在'上*'属性。 –