从arduino获取数据

Hi guys this script gets the data from my arduino.

<script>                        
    var nivel = 0;
    var data_val = 0;                                 

    function GetArduinoInputs()
    {
        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;
                        data_val = this.responseXML.getElementsByTagName('analog')[0].childNodes[0].nodeValue;
                    }
                }
            }
        }
        request.open("GET", "ajax_inputs" + nocache, true);
        request.send(null);
        setTimeout('GetArduinoInputs()', 200);
    }

</script>

But I am not able to read the value of data_val on my other script:

<script>
    var level = data_val;
</script>

Can someone help my out, please

You could use the same approach that you are using to store the value that you get from the server in the local HTML to retrieve the value in the "other script".

//from the "other script"
var level = document.getElementById("input3").innerHTML;