I am trying to call a ajax function from another function. It is
working this way: I send some search criteria to searchRecords and
searchRecords return multiple records and display them in a table.
While displaying the results in the table, I called another function
and pass it the transactionID to get the services done in each
transaction. I am not getting any services back. But the weird part
is that if I put 'alert(serviceType);' right before displaying
serviceType in the table, the servicetypes appear just fine in the
table. I don't know why it works with alert() but not without it. At
first, I was thinking that may there is some delay in getting the
results from the 2nd function and the table is displayed before the
results get back but I tried putting delay code and it still doesn't
work. I think I am missing something small here.
//------------------ 1st function
function searchRecords(form,clientName, staffName, topic,
specificDate, fromDate, toDate, searchService,transactionID,
department)
{
displayClientInfo = form;
var oWddx = new WddxSerializer();
var _o = {form: form, staffName: staffName,
specificDate: specificDate, fromDate: fromDate, toDate: toDate};
DWREngine._execute(_ajaxConfig._cfscriptLocation,
null, 'getRecords', oWddx.serialize(_o), getRecordsResult);
}
//Call back function for searchRecords
function getRecordsResult (r) {
if(r.getRowCount() > 0){
var out = '<br><table border=1 cellpadding=3
cellspacing=3><tr><th>Select</th><th>ID</th><th>Client
Name</th><th>Staff Name</th>';
out= out + '<th>Date</th><th>Service
Type</th>';
....some code here...
getServices(r.id[x]);
out = out + "<td valign='top'> " +
serviceType + "</td>";
}
$('searchResults').innerHTML =out + '</table>';
}
//------------------ 2nd function
function getServices(transID)
{
DWREngine._execute(_ajaxConfig._cfscriptLocation,
null, 'getServiceType', transID, dosomething);
}
//Call back function for getServices
function dosomething (r)
{
serviceType ='';
if(r.getRowCount() > 0){
for (var x = 0; x < r.getRowCount(); x++)
{
serviceType = serviceType + r.service[x]
+ ",";
}
}
}