[英]Synchronous XMLHttpRequest Strophe.js
I am using Strophe.js (JS based Xmpp library).我正在使用 Strophe.js(基于 JS 的 Xmpp 库)。 The problem is that I need to establish synchronous connections so that the responses I receive are in the correct order.问题是我需要建立同步连接,以便我收到的响应顺序正确。 But when I use synchronous connections, the page sort of becomes stuck.但是当我使用同步连接时,页面有点卡住了。 Even a right-click to open the console takes minutes.即使是右键单击打开控制台也需要几分钟。
I get this warning on page:我在页面上收到此警告:
[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. [弃用] 主线程上的同步 XMLHttpRequest 已弃用,因为它对最终用户的体验有不利影响。 For more help, check https://xhr.spec.whatwg.org/ .如需更多帮助,请查看https://xhr.spec.whatwg.org/ 。
Please help!请帮忙!
The warning just tells you that it is greatly preferred to use async calls, for a reason.该警告只是告诉您出于某种原因,最好使用异步调用。
A synchronous call will block the rest of your code until a response has been received.同步调用将阻塞代码的 rest,直到收到响应。 Somehow, it takes a long time for your synchronous call to return.不知何故,您的同步调用需要很长时间才能返回。
Without looking at your code it is hard to tell why, but you could try retrieving the resource you are trying to get by typing its URL in in a browser and see how long it takes to get a response, or if you get a response at all, and if you see any errors.如果不查看您的代码,很难说出原因,但您可以尝试通过在浏览器中键入其 URL 来检索您尝试获取的资源,并查看获得响应需要多长时间,或者您是否在全部,如果您看到任何错误。
If the resource can't be retrieved or is slow in coming, you know where the problem is and where to fix it.如果无法检索到资源或资源获取速度缓慢,您就会知道问题出在哪里以及解决问题的位置。
There are some ways of getting XMLHttpRequest
results in the right order:有一些方法可以按正确的顺序获得XMLHttpRequest
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.