Question

Let's just say I have a text file on website.tld/file.txt. I wish to display it in a web page and since the file changes every so often I want to keep streaming. Moreover, the streaming must be seamless and I do not wish to have the refresh flicker.

Thanks in advance!

Was it helpful?

Solution

If you're using jQuery, this is a really quick thing to add.

window.setInterval(function(){
    $.get('website.tld/file.txt',
        function(data){
            $('#div-where-stream-goes').html(data);
        }
    );
},1000);

This will run once every second, which to me a little much. It could run every five seconds and wouldn't make that much of a difference for the user, and it would be less work on the browser. Just change 1000 to 5000. I don't really like the idea of using a .txt file to get data from, but whatever floats your boat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top