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

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

    报告相同问题?

    悬赏问题

    • ¥15 unity 绘画方面的问题
    • ¥15 FTP 明明给了权限但是还是550 Permission denied问题
    • ¥20 Java的kafka错误unknowHostException
    • ¥20 gbase 8a没有lisense,需要获取一个lisense
    • ¥15 前端的3d饼图不知道用啥框架做的
    • ¥15 算法问题 斐波那契数 解答
    • ¥15 VS2019 SPY++ 获取句柄操作
    • ¥15 Facebook 获取广告
    • ¥15 PID算法的输出结果如何转换成pwm
    • ¥15 java文本解密算法