无法在php脚本上调用JavaScript函数

时间:2017-12-13 08:17:45

标签: javascript getjson

当我在php脚本中调用javascript函数时,它只调用run()但不调用run()的函数。我的JavaScript或php脚本有什么问题吗?

<script type= "text/javascript">

    function run(){
        $.getJSON("http://smartfypwindow.000webhostapp.com/api/led/update.php?id=1&status=Close", function(data) {
            console.log(data);
        });
    }
</script>

<?php

    $dbusername = "id3137057_windowdatabase"; 

    $dbpassword = "root123";  

    $server = "localhost"; 

    $My_db = "id3137057_window";

    // Connect to your database

    $dbconnect = mysqli_connect($server, $dbusername, $dbpassword);

    $dbselect = mysqli_select_db($dbconnect,"id3137057_window");

    $result = mysqli_query($dbconnect, "SELECT temp, hum, lum FROM 
    weather");

    while($row = mysqli_fetch_assoc($result)){

        if($row["temp"] < 27) {
            echo" run()";
        }
    }

    mysqli_close($dbconnect);

?>  

1 个答案:

答案 0 :(得分:0)

如果你真的想采用这种方法......

while($row = mysqli_fetch_assoc($result)){

    if($row["temp"] < 27) {
        echo" <script>run()</script>";
    }
}

这应该有用。