【发布时间】:2018-11-23 05:29:46
【问题描述】:
我很难在 php 中获取特定变量的值以在 js 中使用。这是我在 php 中的代码:
<?php
require("connection.php");
$sql_cmd = "SELECT * FROM tbstatus";
$stmt = $con->prepare($sql_cmd);
$stmt->execute();
echo "<h2>STATUS OF THE BABY</h2>";
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<h4>" . $result['status'] . "</h4>";
}
?>
我想获取 this ($result['status']) 的值并将其传递给 js 中的变量 pos。这是我的js代码:
setInterval(function() {
$("#position").load('refresh.php');
notif();
}, 1000);
function notif() {
var pos = $('PHP VARIABLE HERE').val();
alert(pos);
}
感谢您的帮助。
【问题讨论】:
-
你为什么不试试
echo呢?
标签: javascript php jquery database