我想用jQuery構建表格行並將其附加到現有表格。在我的行構建函數中,我需要根據$.each
循環內的當前值theJSON.EmployeeID
創建另一個Ajax調用。jQuery中的連接Ajax回調不執行?
執行內部$.getJSON
,檢索有效的JSON並觸發其回調,但包含data.Name
的td未連接到trString
! trString
甚至沒有收到空的td,看起來這條線根本不會被執行。我是否缺少明顯的東西,還是我誤用了$.getJSON
,還是什麼?
//This call succeeds and returns valid JSON
$.getJSON("ajax/queries.php?q=licenseMain&oId=" + oId + "&sId=" + sId + "&eId=" + eId + "&inUse=" + inUse + "&page=1", function (licensedata) {
buildLicenseTable(licensedata);
});
function buildLicenseTable(trArray) { //Build table row-by-row
var trString = "";
$.each(JSONforTable, function (key, theJSON) { //Build single table row
trString += "<tr>";
trString += "<td>" + theJSON.LicenseID + "</td>";
trString += "<td>" + theJSON.LicenseNumber + "</td>";
trString += "<td>" + theJSON.LicenseType + "</td>";
//The inner $.getJSON call
$.getJSON("ajax/queries.php?q=employee&eID=" + theJSON.EmployeeID, function (data) {
console.log("*---Callback executing!---*");
trString += "<td>" + data.Name + "</td>"; //<----This line doesn't execute
});
trString += "</tr>";
$("#bigtable > tbody:last").append(trString);
});
}
如何在腳本中定義JSONforTable? – 2011-04-25 14:25:05