jQuery를 사용하여 테이블 행을 빌드하고 기존 테이블에 첨부하려고합니다. 내 row-building 함수 내에서 $.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이 정의되어 있습니까? –