weixin_33725722 2015-01-27 23:58 采纳率: 0%
浏览 165

从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

  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2015-01-28 00:06
    关注

    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;
    
    评论

报告相同问题?