Skip to content Skip to sidebar Skip to footer

Flask App Update Pre Tag With The Contents Of Dynamic Server Log File

Using a logfile that is produced by a long computation and refresh it into a pre tag. Scripted with a JS function (not inline) that can be toggled on or off, instead of always on.

Solution 1:

You need to rewrite the setInterval callback function and add an xhr.onload callback like this:

//global JavaScript Variables herevar timerId;

/*Fetches*/functionrefreshPre(url, blRefresh = true) {
    if (blRefresh) {
        //declare and assign setInterval
        timerId = window.setInterval(function(){ populatePre(url) },1000);
    } else {
        //stop setIntervalwindow.clearInterval(timerId);
        timerId = null; 
    }
}

functionpopulatePre(url) {
    var output = document.getElementById('contents');
    var xhr = newXMLHttpRequest();
    // Listen to xhr events for response:
    xhr.onload = function(){
        output.innerText = xhr.response;
    }    
    xhr.open('GET', url);
    xhr.send();
}

XMLHttpRequest Reference

Post a Comment for "Flask App Update Pre Tag With The Contents Of Dynamic Server Log File"