【发布时间】:2016-05-05 23:13:32
【问题描述】:
我有一个 PHP 文件,它为我的 Angular 数组生成 JSON 数据。根据 GET 请求,数据会有所不同。产生不同数据的两个 URL 包括字符串data.php?c=1 或data.php?c=2。
在初始加载时,我预加载了data.php?c=1,但我不知道如何将新数据动态加载到数组中并在页面上刷新。在示例中,我想单击将触发某些内容以获取新数据的链接。
我真的在为此苦苦挣扎。我什至不确定我的方法是否正确,或者我是否应该在获取新数组后使用 AJAX 重新加载页面内容。
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
(function() {
var app = angular.module('myApp', []);
app.controller('FilesController', function ($scope, $http){
$scope.files = [];
$http.get('http://monstacdn.com/v2/data.php?c=1').success(function(data) {
$scope.files = data;
});
});
})();
</script>
</head>
<body>
<table ng-controller="FilesController">
<tr ng-repeat="file in files">
<td>{{ file.name }}</td>
<td>{{ file.size }}</td>
</tr>
</table>
<p><a href="#" onclick="doSomething('http://monstacdn.com/v2/data.php?c=2')">Change Data</a>
</body>
</html>
【问题讨论】:
标签: javascript php jquery angularjs json