HTTP 同步请求阻止我的 GIF 在 Chrome 和 IE 中移动?
在 Firefox 中,我有一个同步请求发生(它必须是同步的,否则后面的 JS 将无法正确运行),现在在 XMLHttpReq 函数中,它基本上将 DIV 的内容之一更改为一个微小的加载徽标(转动齿轮),以便您可以看到进展...在 FF 中,这可以 100% 异步或同步...Chrome 和 IE 没有这样的运气..?
任何人都可以帮助我或解释为什么吗?我猜这与他们禁用所有其他进程有关,但如果是这样,我怎样才能让它工作或在加载原始 XMLHttpReq 后评估 JS 文件?
In Firefox, I have a synchronous request that happens (it must be sync or the later JS will not run correctly) now in the XMLHttpReq function it basically changes one of the DIV's contents to a tiny loading logo (turning cog) so you can see progress... In FF this works 100% async or sync... Chrome and IE no such luck..?
Can anyone help me or explain why please? Im guessing it something to do with them disabling ALL other processes but if this is so how can i get this to work OR evaluate and JS file after this original XMLHttpReq has loaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有什么理由使用同步 XMLHttpRequest 吗?
同步调用会占用您的浏览器,直到事务完成,这就是建议不要这样做的原因。
您应该考虑对异步调用进行排序。意思是...问题不在于您的异步调用,而在于您
它必须同步的原因,否则后面的JS将无法正确运行
。在 AJAX 回调中设置一个completed
变量非常简单,其他有问题的 JS 可以在执行之前检查该变量。Is there any reason to use a synchronous XMLHttpRequest?
Synchronous calls tie up your browser until the transaction is finished, which is why it is advised against.
You should look at sequencing your asynchronous calls. Meaning... the problem isn't with your asynchronous call, it's in your reason why
it must be sync or the later JS will not run correctly
. Setting acompleted
variable in the AJAX callback is pretty simple to do, which the other problematic JS can check before executing.Frame.js 旨在启用同步请求,而无需挂起浏览器。
其他评论者的说法是正确的,因为浏览器支持较差,真正的同步 AJAX 请求大多毫无用处。 Frame.js 就是为了解决这个问题而设计的。祝你好运。
Frame.js is designed to enable synchronous requests without hanging up the browser.
The other commenters are correct in saying that truly synchronous AJAX request are mostly useless because of poor browser support. Frame.js was designed as a solution to that problem. Best luck.