0
我有一個JavaScript函數,這是我的數據循環基本上我調用循環內的另一個函數,但它只在最後一個索引執行一次這裏是我的代碼和這個函數我想執行每時間。 基本上內環我叫AJAX是在循環,但問題的各項指標運行良好是調用db.transaction功能,只在最後一個索引執行JavaScript函數內循環只運行一次
db.transaction(populateDB,errorCB);
function renderList(tx, results) {
len = results.rows.length;
console.log("rows" + results.rows.length);
for (var i = 0; i < len; i++) {
(function (i) {
var nid = results.rows.item(i).nId;
$.ajax({
type: 'post',
url: 'http://localhost:50972/LibraryService.asmx/GetTitleSections',
dataType: 'json',
data: "{'MainSectionId':'" + nid + "'}",
contentType: 'application/json; charset=utf-8',
async: false ,
success: function (response) {
var data = response.d;
alert(data.nId);
TitleSectionData = data;
},
error: function (error) {
console.log(error);
}
});
db.transaction(TblTitleSection, errorCB);
})
(i);
// htmlstring += '<li>' + results.rows.item(i).strTitle + '</li>';
// $('#resultList').append("<li>" + results.rows.item(i).strTitle + "</li>");
$('#'+i).append(results.rows.item(i).strTitle);
// $('#tblMainSection').append("<tr><td>" + results.rows.item(i).strTitle + "</td></tr>");
}
// $('#resultList').html(htmlstring);
}
沒有不工作ajax運行正常我想執行db.transaction(TblTitleSection,errorCB);這個函數每次迭代 –
啊我看,我看錯了這個問題;)。 console.log(「rows」+ results.rows.length);返回? – cpalinckx
它返回5條記錄 –