我从angularjs中的http.get调用来自js代码的php文件。在Success函数上,结果应该在参数中接收。但它显示收到null。如果我使用简单的回显和收到的字符串参数但是在函数中没有收到sql结果。查询和连接是正确的。我无法找到错误。
js file
app.controller('HomeController',function($scope,$http){
$scope.message="Home";
$http.get('get.php').
success(function(data) {
debugger;
$scope.users = data;
});
});
php文件
<?php
$database = "firstdatabase"; //database name
$con = mysqli_connect("localhost", "root", "");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$state = "SELECT rollno ,name, dept FROM student";
$result = mysqli_query($con, $state);
if ($result) {
$arr = array();
while ($row = mysqli_fetch_array($result)) {
//$r[] = $row['rollno'];
//$n[]= $row['name'];
//$d[] = $row['dept'];
$arr[] = $row;
}
//$rows = array();
// while($row = $result->fetch_row()) {
// $rows[]=$row['name'];
// }
}
echo htmlspecialchars(json_encode($arr));
?>