w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Fire javascript event when file starts to download - when response is received

The simplistic solution would be to set the setTimeout to say 1 second to check whether the response has been received. The setTimeout will repeat until cleared.

So you could do:

var responseReceived, hTimer = setTimeout( function() {
    if( responseReceived ) {
        // code to stop/hide spinner here
        clearTimeout( hTimer );
    }
}, 1000 );

// responseReceived is set when the response is received

Alternatively, what you need is what is called a comet in programming terms. For your needs a Ajax long-poll should suite your needs best. You basically open a ajax request to the server (which is asynchronously) and the callback function does whatever you want when the server responds. Take a look at these references:





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.