嗨,首先对不起我的英文不好。我已经在SO中搜索。但我没有得到我需要的确切答案。 我的问题是我需要同步Ajax请求。我知道我们可以使用“asynch:false”。 但这会使浏览器被锁定。我有一个文件夹树(我使用“tafel树”js)在我的网站。树节点在运行时生成。每次 用户单击一个节点,它将发送请求到服务器并将该节点添加到树中。 但问题是,如果该页面点击F5然后我需要加载我先前已经选择的树结构刷新。 我使用“asynch:false”来实现它。但是这会让浏览器太慢。异步AJAX以有序方式调用
,在这里我有什么
function loadPage() {
/* some other codes are here*/
/* here i call an ajax for get the inside folder list in correct order.(i am usig protoype)*/
new Ajax.Request(ajaxGetInsideFolderIdsUrl,
{
parameters: {branchId: CurrentSelectfolderId},
onSuccess: function(res) {
/* onSuccess i call another function*/
var brs = res.responseText.split(","); // branch ids in correct order.
syncFolder(brs)
}
}
function syncFolder(brs){
for(var i= 0 ; i < brs.length; i ++){
var tempbranch = tree.getBranchById(brs[i].getId());
selectAfterChange(tempbranch)
/*
selectAfterChange function is used for selecting current branch. calling "tafle tree" select() function in side it.
i just created an copy of "select()","_openPopulate()" functions used in "tafle tree" and modified it with "asynch : false ".and now its working fine.
*/
}
}
function selectAfterChange(brs){
brs.chk_select();
/* for selecting the branch (created a copy of current "select()" function used in "tafle tree" js
and modified it with "asynch : false "and now its working fine.) */
showList();// for listing items in side that folder (in another Ajax page).
}
我的问题是,如果用户打开一个长枝。 然后刷新页面会因为同步Ajax调用而花费太多时间加载。 花太多时间对我来说不是一个大问题。但浏览器被锁定,直到所有的请求执行。 有没有其他方法可以做到这一点。
无论您需要使用localStorage的工作,或让你的后台工作,它可以一次返回多个节点。 – epascarello 2013-03-05 03:31:02