想要根据脚本中的值更改按钮文本

时间:2016-01-01 20:03:32

标签: python html webiopi

您好我的webiopi html和脚本有问题我无法更改按钮状态,具体取决于script.py中的值在Chrome控制台中出现此错误

这是自动刷新按钮的时候。

inline

当我按下它时,我得到了。

POST http://192.168.0.108:8000/macros/get_DoorStatus/0 404 (get_DoorStatus Not Found) 

这是index.html代码

Uncaught TypeError: ((n.event.special[e.origType] || (intermediate value)).handle || e.handler).apply is not a function

这是script.py代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
        <link rel="stylesheet" type="text/css" href="style.css">
        <title>WebIOPi | Demo</title>
    <script type="text/javascript" src="/webiopi.js"></script>
    <script type="text/javascript">
    webiopi().ready(function() {
        var content, button;
        content = $("#content");

        // create a button which call HelloWorld with "User,Name" argument
        button = webiopi().createMacroButton("macro", "On", "HelloWorld");
        content.append(button); // append button to content div

        // the previous button will always call HelloWorld with "User,Name" argument
        // you can also create a simple button with your own function 
        button = webiopi().createMacroButton("macro2", "Off", "HelloWorld2");
        content.append(button); // append button to content div

                // create a button which call function to get SwitchStatus from script.py (GPIO 27) 
                button = webiopi().createButton("macro3", "Door", "callMacro_get_DoorStatus");
                content.append(button); // append button to content div

    });



    //webiopi().refreshGPIO(true);

    window.onload = function(){
        callMacro_get_DoorStatus()
        }
               setInterval ("callMacro_get_DoorStatus()", 5000);{
        }

    function callMacro() {
        // call HelloWorld(args)
        webiopi().callMacro("HelloWorld()");
    }

        function callMacro() {
        // call HelloWorld2(args)
        webiopi().callMacro("HelloWorld2()");
    }


        function callMacro_get_DoorStatus(){
                   var args = [0]
                  //Get data form script.py and return it with Callback
        webiopi().callMacro("get_DoorStatus", args, macro_get_DoorStatus_Callback);}

        function macro_get_DoorStatus_Callback(macro, args, data){
                p0 = data.split(" ")[0];
                if (p0==1){
                webiopi().setClass("macro3", "Open");
                webiopi().setLabel("macro3", "Door Open");}
                else{
                webiopi().setClass("macro3", "Closed");
                webiopi().setLabel("macro3", "Door Closed");}
                }

    </script>


</head>
<body>
        <h1 align="center">Switch 1</h1>
    <div id="content" align="center"></div>
        <style type="text/css">
        button {
            display: inline-block;
            margin: 5px 5px 5px 5px;
            width: 160px;
            height: 45px;
            font-size: 24pt;
            font-weight: bold;
            color: black;
        }

</body>
</html>

0 个答案:

没有答案