在javascript中是否有一个事件我可以绑定某种类型的监听器,它会告诉我什么时候在页面上执行所有javascript/jQuery/Ajax?在执行开始的时间和我需要监听器"监听"的时间之间,页面将不会加载/卸载/重新加载等,因此这些事件不起作用.该页面实际上没有做任何事情.单击该按钮并激活一些包含对Web服务的Ajax调用的javascript函数.毕竟,我想改变window.location.但是在我的情况下,在web服务完成之前,window.location正在发生变化.
目前使用setTimeout来实现这一点,但由于有时代码需要比正常运行更多的时间,有时window.location在所有其他javascript完成之前触发.简单的说
<input type = "button"... onclick="doThis();";
function doThis() {
try{
//Contains AJAX calls to web services which is mainly what screws up my timing since it may still be trying to execute stuff when the redirect statement happens
}
catch (e) {
}
//Currently doing setTimeout(redirect, 10000);
//Would like to simply detect when all of the above is done and then redirect.
}
Run Code Online (Sandbox Code Playgroud)
编辑:遗漏了一条至关重要的信息.AJAX调用处于for循环中.对我来说变量和成功回调的使用并不是很好,因为在我的成功回调执行时,我的变量在for循环中采用了新值.
| 归档时间: |
|
| 查看次数: |
1178 次 |
| 最近记录: |