【发布时间】:2018-05-14 20:28:06
【问题描述】:
** 角度 1.X ** 大家好!我需要帮助来使这个 $http.get 函数异步,正如您从代码中看到的那样,我当前的临时解决方案是 setInterval 的 displayData 范围。这显然不是一个有效的解决方案,因为它占用了太多的 CPU、太多的用户数据并且可能导致 UI 上的一些闪烁。我希望在更新数据库时更新数组。 请不要推荐我切换到其他框架。 谢谢
$scope.displayData = function() {
$http.get("read.php").success(function(data) {
$scope.links = data;
});
}
setInterval(function(){$scope.displayData();}, 500);
这是我的 PHP ("read.php")
<?php
include("../php/connect.php");
session_start();
$output = array();
$team_id = $_SESSION['team_id'];
$sql = "SELECT record_id, user_id, link, note, timestamp FROM
link_bank WHERE team_id = '$team_id' AND status = 'valid'";
$result = mysqli_query($connect, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$output[] = $row;
}
echo json_encode($output);
}
?>
【问题讨论】:
标签: php mysql angularjs angularjs-http