简体   繁体   中英

Is it possible to get a javascript event when a flask url_for replies?

Essentially, my code is,

<img src="/video_feed" />

and when you load the website, it takes 20 seconds before the video feed begins.

I'd like to display a loading gif while you wait.
But I'm not sure what event to listen for.

I tried $(window).ready() but that happens immediately. Any idea if there's an event for when the video feed begins?

Or some JS trick? Ajax call that changes div contents on success, maybe, instead of image src?

The video tag isn't working.

Ok worked it out. Made another python route that returns data in a list once it's loaded. In JS, poll until it doesn't get an empty list. When it gets data, then hide the gif.

        var interval = window.setInterval(function(){
            $.getJSON('/ready', function(data){
                if (data.length != 0) {
                    $("#animation").hide().css("visibility", "hidden");
                    clearInterval(interval);  // stop checking it
                }
            })
        }, 1000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM