0

I am using jquery to auto update a part of the HTML page. Following is the code

$(document).ready( function() {
  $('#auto').load("static/l.txt");
  refresh();
});

function refresh() {
  setTimeout(function() {
    $('#auto').load("static/l.txt");
    refresh();
  }, 1000);
}

The id of the HTML div tag to be updated is auto The file static/l.txt is continuously being updated by another python program.

But when I load the html page , the div only gets updated once and does not update the value until and unless I open the developers console on the browser.

I am hosting the web page using Flask in python

davidism
  • 121,510
  • 29
  • 395
  • 339
Taksh
  • 21
  • 5

2 Answers2

0

How about trying this?

var counter =0 ; 

$(document).ready( function() {
  $('#auto').val("starting");
  refresh();
});


function refresh() {
   setInterval( function() {
   counter ++;
    $('#auto').val(counter);
  }, 1000);
}
Kinnison84
  • 176
  • 1
  • 8
  • I am uploading data from a file (coordinates to be precise) . The coordinates are being fetched by another python program.And I want to use those coordinates – Taksh Dec 12 '18 at 11:55
0

Use a callback to know, when the content is actually loaded and move the function definition in the ready block, also.

$(document).ready(function() {        
    function loadData() {
        $('#auto').load('static/l.txt', function(completed) {
            setTimeout(loadData, 1000);
        });
    }

    loadData();
});
Sergej
  • 2,030
  • 1
  • 18
  • 28