Hello everyone, I have a script that retrieves data from my Arduino board.
<script>
var level = 0;
var dataValue = 0;
function fetchArduinoData()
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
if (this.readyState == 4) {
if (this.status == 200) {
if (this.responseXML != null) {
document.getElementById("input3").innerHTML = this.responseXML.getElementsByTagName('analog')[0].childNodes[0].nodeValue;
dataValue = this.responseXML.getElementsByTagName('analog')[0].childNodes[0].nodeValue;
}
}
}
}
request.open("GET", "ajax_inputs" + nocache, true);
request.send(null);
setTimeout('fetchArduinoData()', 200);
}
</script>
However, I am facing an issue where I cannot access the value stored in dataValue
on another script:
<script>
var currentLevel = dataValue;
</script>
Can someone please assist me with this problem?