I am trying to fetch data from mysql into php and returning it in json format to an controller(angular).
While json creation, some unwanted string is getting appended because of which i am getting error while traversing the json.
Following is my php code:
$json_response = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_array["name"] = $row["name"];
$row_array["quantity"] = $row["quantity"];
array_push($json_response,$row_array);
}
echo json_encode($json_response);
And following is the console output after printing the json(console is in controller) :
{itemData:{"data":[{"name":"item1","quantity":"10"},{"name":"item2","quantity":"20"},{"name":"item3","quantity":"25"}]
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
}}
Above the highlighted part is coming in the json, because of which the error is happening.
Please help me to resolve the issue.
exit();after theecho json_. In case that doesn't help - try using a different host or contact them.