I've been trying to solve a coding issue for some days now. I can't figure out how this asynchronous coding works despite reading several posts.
Hopefully someone on here can point me in the correct direction. Below is what I'm trying to achieve, seems though that I can't pass a responseText into a var.
Comparing responseText like this works: if (this.responseText > 10) {do something;}
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
var peak;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("value").innerHTML = this.responseText;
if (this.responseText > peak){
document.getElementById("valuePeak").innerHTML = this.responseText;
peak = this.responseText;
}
}
};
xhttp.open("GET", "/value", true);
xhttp.send();
}, 55 ) ;