如何在标志变为真之前暂停 javascript 执行?
例如,我有这样的 xml 消息:
[...]
<action>
<resource update>id</resourceupdate>
</action>
<action>
<event>id1</event>
</action>
<action>
<event>id2</event>
</action>
<action>
<event>id3</event>
</action>
[...]
我希望仅在处理节点资源更新之后才处理事件节点(这需要更多时间来提供服务,因为它需要加载页面):
在javascript中使用迭代器(每个)处理此消息,我尝试过:
$(_response).find('ACTION').each(function() {
if (tagName=="RESOURCEUPDATE") {
ready = false;
//load the resource with selected id in an iframe
} else if (tagName=="EVENT") {
browserLoaded(); //the waiting function
eventhandler(); //consume the event
}
});
等待函数是:
function browserLoaded() {
if (!ready) {
setTimeout(browserLoaded(),1000);
}
}
并且当 iframe 加载时 ready var 变为 true:
$(iframe).load(function() {
ready = true;
});
但是当执行时我会发现这个错误:
Maximum call stack size exceeded error
有任何想法吗?谢谢!