我是phonegap应用程序开发的新手。我想创建一个应用程序,将通信(CRUD操作)与服务器。我已经创建了一个json使用php。现在我想用angularJS访问这个文件。但无法从服务器访问该文件("http://apptest.byethost5.com/view.php")。但是localhost给了我正确的结果。我想那个文件的权限有问题。我已将文件权限更改为755,但这不起作用。你能建议处理这个问题的正确方法吗?
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.firstname }}</td>
<td>{{ x.lastname }}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://apptest.byethost5.com/view.php")
.then(function (response) {$scope.names = response.data.records;});
});
</script>
</body>
如果被请求的页面在不同的服务器上,那么出于安全原因,该服务器必须显式地允许跨域请求
添加到view.php的顶部
header("Access-Control-Allow-Origin: *")