Error while json creation in php -


i trying fetch data mysql php , returning in json format controller(angular).

while json creation, unwanted string getting appended because of getting error while traversing json.

following 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 console output after printing json(console 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 highlighted part coming in json, because of error happening.

please me resolve issue.

ok, after having little research can confirmed comment right. code fine , json string being created by code alright.

however, unwanted appended string:

<!-- hosting24 analytics code --> <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script> <!-- end of analytics code --> 

is being appended server. believe it's free server , therefore allow inject own code website. have mechanism append script every request being made server (including ajax requests).

since code being added server, seems there's nothing can in code overcome it. seems option hosting company or having paid plan.

update - can try , use exit(); function right after printing json string. might break host's injection.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -