Skip to content Skip to sidebar Skip to footer

How To Display 'loading' When Making A 'synchronous' Ajax Call In Pure Javascript?

I want to make sure the result is shown to user, so I make synchronous AJAX call. It's quite simple to display a 'Loading' indicator with asynchronous AJAX (the examples are everyw

Solution 1:

It's "impossible" because Javascript is single-threaded, and the synchronous call blocks updates to the UI.

However, you may be able to display an animated 'loading' graphic before launching the synchronous AJAX call, and removing it upon success or failure. I believe most browsers will be able to continue rendering the animated gif even while technically blocked for the synchronous call.

Solution 2:

It is possible, see the top answer here: How to show waiting message during sync ajax call in browser

The solution is to show your loading message, hand control back to the browser, and then lock everything up with your synchronous remote call. One way to do this is to use setTimeout with a delay of zero

Post a Comment for "How To Display 'loading' When Making A 'synchronous' Ajax Call In Pure Javascript?"