Hello,
I'm having some problems with my jQuery script. It works correctly except it doesn't wait for the internal AJAX request to return before adding the variable data 'daa' to the HTML table variable. I debugged it a bit using 'alert' and I think it's adding the 'daa' data to the end of the table (after the '</table>'). Any help is appreciated, thanks.
function getPage(header, curSet, perSet, table, indexes, callback) {
$.get('api.php?act=loadRecords&table='+table+'&curSet='+curSet+'&perSet='+perSet+'&indexes='+indexes, function(data) {
var json = jQuery.parseJSON(data);
var ret = "<table cellspacing='0' cellpadding='0'><tbody>";
var catID = findCategory(indexes);
ret += header;
for (var i=0;i<json.length;i++) {
ret += "<tr>";
for (var td=0;td<json[i].length;td++) {
if (td == catID) {
$.get('api.php?act=getCategoryName&cid='+catID, function(daa) {
ret += "<td>"+daa+"</td>";
});
}else
ret += "<td>"+json[i][td]+"</td>";
}
ret += "</tr>";
}
ret += "</tbody></table>";
callback(data = ret);
});
}