异步AJAX按顺序调用
Asynchronous AJAX Calls in orderd manner
你好,首先为我糟糕的英语道歉。我已经在SO中搜索了。但我没有得到我想要的确切答案。我的问题是我需要同步的Ajax请求。我知道我们可以使用"asynch: false "。但这将使浏览器锁定。我有一个文件夹树(我使用"tafel树"js)在我的web。树节点是在运行时生成的。每一次用户单击一个节点,它将向服务器发送请求并将该节点添加到树中。但问题是,如果页面刷新点击f5然后我需要加载我之前已经选择的树结构。我使用"asynch: false "实现了它。但是这会使浏览器太慢。
这里是
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调用。花太多时间对我来说不是什么大问题。但是浏览器会被锁定,直到所有的请求都被执行。还有其他方法吗?
我不熟悉您正在使用的树库,但一般来说,您解决这个问题的方法是将当前扩展的路径存储在浏览器中(本地存储,或cookie,或其他地方),当您刷新页面时,只加载可见的节点。
假设用户当前正在查看路径1/2/3/4。您将该路径保存在某个地方,然后当页面再次加载时,通过拆分路径并逐个附加路径的组件,创建要从后端请求的路径队列:
["one", "one/two", "one/two/three"]
然后发送"one"的AJAX请求,当您获得结果返回时,更新树中的节点,并发送"one/two"的请求。当该请求返回时,更新树,并发送"one/two/three"的请求。
根据你的设计,你可以开始用更多的异步请求填充树的其余部分…
相关文章:
- 阻止在select2单击时调用ajax
- 调用Ajax并返回响应
- Ajax:只在元素存在的情况下调用Ajax
- PHP,MySQL,AJAX-调用AJAX结果后,Bootstrap CSS样式不会显示
- 调用Ajax内部的函数
- 无法获取属性'的值;拆分'在IE8中调用ajax之后
- 我们如何在Firefox中调用AJAX
- Rails:通过调用Ajax重定向
- Cookie 在 Spotify (Javascript) 中调用 ajax 后未保存
- 通过调用 Ajax 来设置 struts bean 值
- 无法从服务器中的 php 调用 Ajax 函数
- 如何在附加表行时调用 ajax
- 如何按顺序调用延迟函数
- 使用Node中的Q promise库对值数组顺序调用/执行相同的函数;并返回带有结果的新数组/集合
- 在facebook用户发送邀请请求后调用ajax调用
- 从顺序 jQuery ajax 调用返回承诺
- 如何按顺序调用一堆包含 ajax 的函数
- PHP按顺序执行ajax调用
- 异步AJAX按顺序调用
- 如何按顺序调用ajax函数