问题
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