using angularjs to get data from sql via php delivered in json. when i hit the php page directly, i see the json results beautifully, but with my angular http call, all i get is an empty array.
sql.php:
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("localhost", "****", "****", "****");
if(!$conn){
die("Connection failed: " .mysqli_connect_error());
}
if($_GET['q'] == 'classes') {
$query = "SELECT * FROM `assignments`";
}
if($_GET['q'] == 'allContacts') {
$query = "SELECT * FROM `contacts`";
}
$data = array();
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
} else {
echo "0 results";
}
$json = json_encode($data);
echo $json;
angular js:
$scope.classes = []
$http.get("sql.php?q=classes")
.then(function(res) {
$scope.classes = res
}, function(err) {
console.log(err)
})
console.log($scope.classes)