I have created a javascript object and associated method which looks very similar to this. "getUserInfo" is executed in $().ready(function(){}
function userObject(userId)
{
this.userId = userId;
this.getUserMachineList = function(infoId, machineListId)
{
jQuery.post(machDBPHPPath + "/listAllUserMachineAccess.php",
{ userId : this.userId, sid : Math.random() },
function(xmlDoc)
{
var userMachineListXml = document.createElement("xml");
//populate serialized xml in dom element here
}
});
}
I am trying to read the content of the populated xml element, in populatePage(), see below.
The problem is (I'm sure many of you have seen this before), is that the xml element created by "getUserInfo" does not exist when I call populateUserPage, which is doing further ajax calls based on information in this xml element.
$().ready(function()
{
//create sessionUser here..
sessionUser.getUserMachineList(USER_MACHINE_INFO_ID, USER_MACHINE_XML_ID);
populatePage();
});
I've used setTimeout with populatePage, as a workaround in the past, but don't like this- it's a hack, and doesn't always work.
Ideally there's some method to wait for this id to exist in the DOM that I don't know about, which would be great, but haven't found as of yet..
Or this could be a general web-design flaw, and I should redesign my server side code to take into consideration this asynchronous-ness?
Thanks for your help..
-Larry