【问题标题】:Reload table automatically from mysql with angular使用角度从mysql自动重新加载表
【发布时间】:2018-03-26 13:17:17
【问题描述】:

我从我的 mysql 数据库中调用一个带有角度的 http.get(url) 的信息,最后用该信息填充一个表。

这是可行的,但现在我希望控制器在数据库发生更改时自动调用 http.get(url) 而无需手动刷新页面。

评论或提示很受欢迎 :D (我是 Angular 的新手)。

这是我目前的代码:

数据.js

angular.module('demo', [])
.controller('Hello', function($scope, $http, $timeout) {

$scope.loadData = function(){

$http.get('http://localhost:8888/nuevo/respuesta.php').
    then(function(response) {
        $scope.greeting = response.data;
        //console.log($scope.greeting);
        //console.log("hola");
    });

};//se cierra la funcion

$scope.loadData();
});

index.html

<div ng-controller="Hello">

        <table>
            <tr>
                <th>ID</th>
                <th>Banda</th>
                <th>Cancion</th>
            </tr>
            <tr ng-repeat="x in greeting">
                <td>{{x.`enter code here`IdCancion}}</td>
                <td>{{x.Bandas_Musicales}}</td>
                <td>{{x.Canciones}}</td>
            </tr>
        </table>
        <button ng-click="loadData()">reload</button>
    </div>

【问题讨论】:

  • 显示一些代码。它会增加您获得帮助的机会。
  • 哦,对不起,给你。

标签: php mysql angularjs


【解决方案1】:

为了将服务器上的数据更改通知您的客户端,您需要找到一种方法让服务器与客户端联系。一个流行的解决方案是 websockets,也许研究一下。此外,一些 php 框架已经为此做好了准备。
如果您不想使用 websockets,您可以考虑每 x 秒刷新一次表数据,以使其保持最新状态。

【讨论】:

  • 感谢您的回答?我会看看 websockets :)
猜你喜欢
  • 2022-01-12
  • 1970-01-01
  • 2018-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2017-10-22
相关资源
最近更新 更多