简体   繁体   English

不建议在主线程上使用同步XMLHttpRequest。 在打开新页面之前可以发送请求吗?

[英]Synchronous XMLHttpRequest on the main thread is deprecated. Any alternative to send request before opening new page?

as the synchronous XMLHttpRequest is being deprecated, I'm wondering if there is some kind of alternative to simulate similar behaviour as non-blocking asynchronous XMLHttpRequests are not suitable for some cases. 由于不建议使用同步XMLHttpRequest,因此我想知道是否存在某种替代方法来模拟类似的行为,因为非阻塞异步XMLHttpRequest在某些情况下不适合。

I'm talking in particular about a case where I need to send a Post Request to the server, when an user clicks a hyperlink. 我特别是在谈论一种情况,当用户单击超链接时,需要将发布请求发送到服务器。 Using PreventDefault is not an option here. 这里不是使用PreventDefault的选项。 With Synchronous XMLHttpRequest I can use an OnClick event, send the Request, and once it's done the browser continues it's default behaviour. 使用Synchronous XMLHttpRequest,我可以使用OnClick事件,发送请求,完成后浏览器将继续其默认行为。 Having the Request asynchonous, would have random results, as everything depends on how quick the new page loads so the Request can finish or not. 使请求异步,将产生随机结果,因为一切都取决于新页面的加载速度,因此请求是否可以完成。

Is there any "modern" way how to freeze the browser's default behaviour till the Post Request finished? 有什么“现代”方式可以冻结浏览器的默认行为,直到“发布请求”完成?

Greetings and thanks. 问候和感谢。

在回调中:

window.location.href = "new url"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不赞成在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated 不推荐在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated $.get 不是 function,不推荐使用主线程上的同步 XMLHttpRequest - $.get is not a function, Synchronous XMLHttpRequest on the main thread is deprecated 不推荐使用主线程上的Firebase同步XMLHttpRequest - Firebase Synchronous XMLHttpRequest on the main thread is deprecated XMLHTTPRequest错误:不建议在主线程上使用同步XMLHttpRequest…(SoundCloud API) - XMLHTTPRequest Error: Synchronous XMLHttpRequest on the main thread is deprecated … (SoundCloud API) 使用jQuery加载外部javascript并禁止“不建议在主线程上使用同步XMLHttpRequest…” - Loading external javascript with jQuery and suppress “Synchronous XMLHttpRequest on the main thread is deprecated…” jQuery load()错误:不推荐使用主线程上的同步XMLHttpRequest - jQuery load() error : Synchronous XMLHttpRequest on the main thread is deprecated 向后移动会导致错误:““不赞成在主线程上使用同步XMLHttpRequest…” - moving backward causes error: "“Synchronous XMLHttpRequest on the main thread is deprecated…” 主线程上的同步 XMLHttpRequest 在嵌入式 Javascript 代码中已弃用 - Synchronous XMLHttpRequest on the main thread is deprecated within embedded Javascript code 主线程上的同步XMLHttpRequest已弃用...尝试了许多不同的解决方案 - Synchronous XMLHttpRequest on the main thread is deprecated… Tried many different solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM