I am retrieving data from database to display it in label.
let work_type = "cooking";
let xmlhttp = createXMLHttp();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("work_cost").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "../php/functions.php?type=" + work_type , true);
xmlhttp.send();
console.log(document.getElementById("work_cost").innerHTML);
The problem is that console.log displays previous data even though label "work_cost" changes perfectly. How can I get real label value that I see?
For example: 1. I get "2" from server. 2. Place "2" in my label 3. console.log (label.value) displays "undefined". 4. Dropdown menu changes 5. I go to server again, get "3" now 6. Place "3" in label. 7. Try to console.log(label.value). I expect to see "3" because thats what I see in my webpage but console says "2"
So it seems like console sees one step previous only.