Question

I'm trying to post values from a file to a textfield on a website. These values will be updated every 5 seconds. I am able to read the values using xmlHTTPrequest, however, when I try to use setInterval to run the function again, the values don't change. It detects if the file is no longer there, but as I put it back and change values, they are the same as before. This is my code:

 setInterval(getrecent, 5000);


        function getrecent () {
        sourcestr = "../userdata/" + sessionStorage.getItem("DoB");
        var x = new XMLHttpRequest();
        x.open("GET", sourcestr + "/recentdata.txt", false);

        x.send();
        if (x.status == 404) {
            document.getElementById("babypic").src = "../../Notrunning.png";
        }
        else {
            var myTextfile = x.responseText;
           // alert(myTextfile);

            document.getElementById("babypic").src = sourcestr + "/picture.jpeg" + '?rand=' + Math.random();
            var split = myTextFile.split(" ");
            document.getElementById("pulse").value = split[0];
            document.getElementById("resp").value = split[1];

        }
     }

I found the error but I'm not sure what to do with it. "Uncaught referenceerror, myTextFile not defined" on row 117 which is "var split = myTextFile.split(" ");


Solved: Added "meta http-equiv="cache-control" content="no-cache" " to the head to avoid caching and corrected spelling of myTextFile. Website works just fine now.

Was it helpful?

Solution

You have written the variable myTextfile in two different casing: myTextFile and myTextfile are not identical variables.

Please correct the casing and think about using an IDE that can point out such errors, it will make your life a lot easier!

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