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

时间:2015-10-21 00:09:40

标签: php angularjs

有人可以帮帮我吗? 我正在做一个来自angular的$ http请求,请求一个php脚本从mysql中检索数据。在php字符串中,我组成了一个Json,例如:

$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;

我的角度控制器......是

.then(function successCallback(response) {
$scope.data=response.data;

产生这个

    <!-- --> {"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"}
    ]} 

...它给了我一个以空注释html标签为前缀的字符串

我是否需要手动删除该前缀并将其余字符串转换为对象,因为angular无法以此格式将对象读取为数组?

我做错了什么,我完全迷失了......我是新来的。提前谢谢!

0 个答案:

没有答案