What I am trying to achieve:
- Use ajax to get a set of result. (id, name e.t.c)
- use id on 1 to make another ajax call, this is in function however.
- in the success function of 1, call 2.
Such that result in 2 is a subrow of 1.
Problem is that jQuery is appending 2 after result one. I expect it to do
result-set-1, result-set-1-subrow;
result-set-2, result-set-2-subrow;
etc
however it is displaying
result-set-1,
result-set-2,
result-set-1-subrow,
result-set-2-subrow
Here is my code
$.ajax({
url: ws_url + 'sessions',
success: function(result) {
$.each(result, function(index, value) {
$('#sessions').append('<tr class="details-control"><td>' + value.sessionName + '</td><td>' + value.sessionDate + '</td><td>' + value.startTime + ' - ' + value.endTime + '</td><td>' + value.Room + '</td></tr><tr><th colspan=5>Talks</th></tr><tr><th>Talk Name</th><th>Start Time</th><th>End Time</th><th>Speaker(s)</th></tr>');
getTalks(value.sessionID);
});
}
});
});
function getTalks(sessID) {
$.ajax({
url: ws_url + 'talks&sessID=' + sessID,
success: function(result) {
if (result !== "null" && result !== "undefined") {
$.each(result, function(ind, val) {
$('#sessions').append('<tr><td>' + val.talkName + '</td><td>' + val.startTime + '</td><td>' + val.endTime + '</td><td>' + val.speakers + '</td></tr>');
});
} else {
$('#sessions').append('<tr><td colspan=5> No Talks </td><td>');
}
}
});
}
<table id="sessions" class="table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Date</th>
<th>Time</th>
<th>Room</th>
</tr>
</table>