Javascript angularjs没有返回php数据,尝试了一切
我正在学习Angularjs,我一直在努力从PHP文件中获取数据Javascript angularjs没有返回php数据,尝试了一切,javascript,php,angularjs,Javascript,Php,Angularjs,我正在学习Angularjs,我一直在努力从PHP文件中获取数据 <head> <script> var app = angular.module("new",[]); app.controller("control",function($scope,$http){ $http.get("index.php").then(function(response) { $scope.database = response.data
<head>
<script>
var app = angular.module("new",[]);
app.controller("control",function($scope,$http){
$http.get("index.php").then(function(response) {
$scope.database = response.data;
});
});
</script>
</head>
<body ng-app="new">
<div ng-controller="control">
<h1>{{database}}</h1>
</div>
</body>
var-app=angular.module(“新的”,[]);
app.controller(“控制”,函数($scope,$http){
$http.get(“index.php”).then(函数(响应){
$scope.database=response.data;
});
});
{{数据库}}
这是我写的有棱角的剧本。我的php代码非常简单
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
echo "How are you?";
?>
我无法使用angularJS将php数据获取到html文件中。
我检查了两次代码,似乎什么都没有丢失。我甚至尝试了json\u encode()
。我错过什么了吗
在所有这些之前,请使用控制台检查右侧宫殿中的php文件
在php代码中
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
echo json_encode("How are you?");
exit();
?>
检查您的网络选项卡(控制台选项卡,您可以在其中检查js错误),是否实际触发了调用检查了响应状态?也许文件请求以某种方式失败了?
$http.get("call.php").then(function(response) {
$scope.database = response.data;
});