Could someone help me please? I am doing a $http request from angular, requesting a php script to retrieve data from mysql. Within the php string I compose a Json such as:
$outp="";
$result=$con->query($sql);
while ($obj=$result->fetch_array(MYSQLI_ASSOC)){
if ($outp != "") {$outp .= ",";}
$outp .= '{"name":"' . $obj["LegalEntityLongName"] . '",';
$outp .= '"distance":"'. $obj["Distance"] . '",';
$outp .= '"latitude":"'. $obj["Latitude"] . '",';
$outp .= '"longitude":"'. $obj["Longitude"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$result->free();
$con->close();
echo $outp;
My angular controller ...is
.then(function successCallback(response) {
$scope.data=response.data;
produces this
<!-- --> {"records":[
{"name":"Shadana Kitchen","distance":"0.5448844737134834","latitude":"-33.8053","longitude":"151.18"},
{"name":"The Good Green Grocer","distance":"1.1798241450689664","latitude":"-33.8075","longitude":"151.173"},
{"name":"Eco Herbs","distance":"2.334899775995475","latitude":"-33.81","longitude":"151.161"},
{"name":"Marc Smith ","distance":"3.2245850404758944","latitude":"-33.8051","longitude":"151.15"}
]}
... it gives me a string prefixed by an empty comment html tag
Do I need to manually remove that prefix and convert the rest of the string into an object, as angular cannot read the object as an array in this format?
What am i doing wrong, I am totally lost...I am new here. Thanks in advance!