doufen9815 2015-10-21 00:09
浏览 29

PHP echo返回一个Json组成的字符串,前缀为:<! - - >

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程