I currently have a script that checks my server information. They have provided a file called index.php - when I load this file in the URL, the content of an .xml file is generated.
My question is, how can I get data from this php file/URL in my Controller?
I use the php url in script but its not working.
Controller.js
var Factory = angular.module('Factory ', ['ngRoute']);
Factory .controller('Controller', function ($scope, $http, $route)
{
$http.get('http://example.com/index.php')
.success(function (data) {
$scope.data = data;
})
.error(function (data, status) {
$scope.data = data || "FALSE";
alert("error");
});
});
index.php
<?php
$mysqli = new mysqli('example.com','abc_5','gf#$6','example_db');
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("DROP PROCEDURE IF EXISTS SP_getName") ||
!$mysqli->query('CREATE PROCEDURE SP_getName() BEGIN SELECT Name from user_tbl END;')) {
echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$result = $mysqli->query("CALL SP_getName()");
while($row = mysqli_fetch_assoc($result)) {
$output[] = array_map('utf8_encode', $row);
}
print(json_encode($output));
?>
I try to call the data from the service, I get nothing. I understand that the query is asynchronous but I am having a hard time understanding how to populate the $scope variable once the data is returned.