I am pulling data from WebAPI and trying to display in a table format in a dialog. WebAPI is called on a btton click. On the first click, the dialog always is blank. From the second click onwards, i can see the data iun tabular format. On the first click ,i can see that the data is coming through from WebAPI. It still shows a blank dialog. What can i do tix this issue?
Thanks in Advance
<input id="prevApps" type="button" value="Previous Apps"
class="divHHoldRowPmtEditinput" onclick="LoadPreviousApplications();" />
function openDialogPrevApps(titlemessage) {
$(document.body).append('<div id="gridPreviousApps"></div>');
$(document.body).append('<table id="tblPrevApps"></table>');
$('#gridPreviousApps').dialog({
autoOpen: false,
hide: "false",
title: titlemessage,
width: 800,
buttons: {
'Ok': function () {
$(this).dialog('close');
}
}
});
$('#gridPreviousApps').dialog("open");
}
function LoadPreviousApplications() {
var hHoldtext = getSelectedHouseholdIDFromUC();
var loginPar = {
UserName: 'myUser',
CompanyID: 'myCompany',
HouseholdID: hHoldtext,
ProgramID: ''
}
$.ajax({
type: 'POST',
url: '/api/Payment/GetPreviousApplications',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(loginPar),
success: function (data) {
var divRow = '';
$("#tblPrevApps tr").remove();
$('#tblPrevApps').append($('<tr>')
.append($('<th>').append("ApplicationID"))
.append($('<th>').append("ApplicationDate"))
.append($('<th>').append("Household"))
.append($('<th>').append("ClientName"))
.append($('<th>').append("Status"))
.append($('<th>').append("StatusDate"))
.append($('<th>').append("ServiceItem"))
)
$.each(data, function (i, item) {
$('#tblPrevApps').append($('<tr>')
.append($('<td
class="divModalDialogSpanColumn">').append(item.ApplicationID))
.append($('<td
class="divModalDialogSpanColumn">').append(item.ApplicationDate))
.append($('<td
class="divModalDialogSpanColumn">').append(item.HouseholdID))
.append($('<td
class="divModalDialogSpanColumn">').append(item.ClientName))
.append($('<td class="divModalDialogSpanColumn">').append(item.Status))
.append($('<td
class="divModalDialogSpanColumn">').append(item.StatusDate))
.append($('<td
class="divModalDialogSpanColumn">').append(item.ServiceItem))
)
});
$('#gridPreviousApps').append($('#tblPrevApps'));
openDialogPrevApps('Previous Applications');
},
failure: function (data) {
},
error: function (data) {
}
});
}
tblPrevApps
doesn't exist until you runopenDialogPrevApps()
yet you appear to try and append items to this table. I suspect it is blank due to no content being hung in the table the first time around. The second time, the table now exists and can be appended to.