// Need these to be stuffed full of data!
listHash[options.Alias] = hashTable;
return listHash[options.Alias];
These two lines are executed within the callback function when the request
finished. Where does the return value go to? Since it's an asynchronous
request, the function that started the request has ended execution long
ago. And did return nothing (more precisely: undefined). So the return
value of the callback function goes to the caller. That is some part of
jQuery. Probably not what you intended.
So you need to be able to notify the original caller. Here is an idea of
what you could do:
// extend the parameter list with a callback function
GetHashTable: function( listName, options, callback ) {
// [snip]
if ( listHash.hasOwnProperty(options.Alias) && !options.RefreshData ) {
// instead of returning, call callback
callback(listHash[options.Alias];
return;
}
if ( options.Async ) {
// asynchronous
$.ajax({
// [snip]
complete: ( options.hasOwnProperty('FormatData') ?
options.FormatData :
function(xData, Status) {
// [snip]
listHash[options.Alias] = hashTable;
// again, instead of returning, call callback
callback(listHash[options.Alias];
} /* end completefunc */ ) //end ternary
});
} else {
// synchronous
$.ajax({
// [snip]
complete: ( options.hasOwnProperty('FormatData') ?
options.FormatData :
function(xData, Status) {
//console.log(Status);
//console.log(xData.responseText);
$(xData.responseXML).find("[nodeName='z:row']").each(
function () {
var $node = $(this);
if ( options.Split ) {
hashTable[$node.attr("ows_ID")] =
$node.attr("ows_" + options.ViewField).split(options.Split.Delimiter ||
";#")[options.Split.Index || 1];
} else {
hashTable[$node.attr("ows_ID")] =
$node.attr("ows_" + options.ViewField);
}
}); // findrows
} /* end completefunc */ ) //end ternary
});
listHash[options.Alias] = hashTable;
// to be consistent, you might call the callback here as well
//callback(listHash[options.Alias];
return listHash[options.Alias];
}
},
Now the caller of that function has to be adapted to not expect a return
value, but to wait for the callback to be called.
Hope that helps,
Matt
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]