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

左心房为你撑大大i 提交于 2020-01-06 14:46:17

问题


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.

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. With Synchronous XMLHttpRequest I can use an OnClick event, send the Request, and once it's done the browser continues it's default behaviour. 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.


回答1:


In the callback:

window.location.href = "new url"


来源:https://stackoverflow.com/questions/36272753/synchronous-xmlhttprequest-on-the-main-thread-is-deprecated-any-alternative-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!