How to display “Download” when creating a “synchronous” AJAX call in pure JavaScript?

I want to make sure the result is shown to the user, so I am making an AJAX synchronous call. It is very simple to display the “Download” indicator with asynchronous AJAX (examples are everywhere), but when I use the synchronous AJAX call with XMLHttpRequest, the GIF image of the download indicator does not appear at all.

Some said that when making a synchronous call, it is impossible to display an indicator (block until a response is received from the server). But I just want to ask if there is a way to do this.

+4
source share
2 answers

This is not possible because Javascript is single-threaded and a synchronous call blocks UI updates.

However, before starting an AJAX synchronous call, you can display the animated download schedule and delete it if it succeeds or fails. I believe that most browsers will be able to continue rendering an animated gif even with technical blocking of a synchronous call.

+7
source

Perhaps see the main answer here: How to show a waiting message while synchronizing an ajax call in a browser

The solution is to show your boot message, manually control it back to the browser and then block everything with your synchronous remote call. One way to do this is to use setTimeout with a zero delay

0
source

Source: https://habr.com/ru/post/1379759/


All Articles