[英]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.