填充xml元素我已創建javascript對象和相關聯的方法,該方法看起來非常相似,這一點。 「getUserInfo」 在$())執行。就緒(函數({}使用從AJAX
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
}
});
}
我想讀的人口XML元素的含量,在populatePage(),見下文。
的問題是(我敢肯定,你們中許多人之前已經看到這一點),是由「getUserInfo」創建的XML元素,當我打電話populateUserPage,這是基於在該XML元素的信息做進一步的Ajax調用不存在。
$().ready(function()
{
//create sessionUser here..
sessionUser.getUserMachineList(USER_MACHINE_INFO_ID, USER_MACHINE_XML_ID);
populatePage();
});
我使用的setTimeout與populatePage,作爲PAS解決方法噸,但不喜歡這 - 這是一個黑客,而並不總是有效。
理想的情況下有一些方法,以等待在我不知道的DOM,這將是巨大的,但還沒有找到作爲尚未存在這個ID ..
或者這可能是一個一般的網頁設計缺陷,我應該重新設計我的服務器端代碼考慮到這種異步的煩躁?
感謝您的幫助..
拉里