I asked almost the same question a long time ago ( here ), and the famous TJ Crowder offered an amazing solution. The client (page) provides an additional parameter when requesting a file. An optional parameter should be some random string. Then you start your modal dialog "Wait ...".
Now, from the server, when you prepare the answer, you set a cookie for the value of this additional parameter. The client, in turn, must start a timer interval that simply looks at document.cookieevery 100 milliseconds or so, checking this random value. As soon as the cookie contains a random value, you know that the HTTP response came from the server! At this point, you can hide the modal dialog or something else.
source
share