无法在 php 脚本上调用 JavaScript 函数
Can't call a JavaScript function on a php script
当我在 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);
?>
如果你真的想采用这种方法...
while($row = mysqli_fetch_assoc($result)){
if($row["temp"] < 27) {
echo" <script>run()</script>";
}
}
这应该有效。
当我在 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);
?>
如果你真的想采用这种方法...
while($row = mysqli_fetch_assoc($result)){
if($row["temp"] < 27) {
echo" <script>run()</script>";
}
}
这应该有效。