I have a php (history.php) that creates a json
$i=1;
$q=mysql_query("select * from participants where phone='".mysql_real_escape_string($_GET['phone'])."' limit 10");
while($rs=mysql_fetch_array($q)){
$response[$i] = $rs['code'];
$i++;
}
print json_encode($response);
exit;
In js I access this file:
var req=$.get("history.php", { phone: "" + phone + ""},
function(data) {
//data="1":"code1","2":"code2","3":"code3","4":"code4","5":"code5"};
var msg = "";
for(i=1;i<=5;i++){
msg+= "<li>"+data[i];
}
$(form_message).html(msg);
})
After this code is executed my output is
which means that 'data' is not passed as an array.. it's passed like a string. But if I uncomment the data var in js everything is ok. The output is:
Can you please tell me what am I doing wrong when passing the data from php.
Thanks in advance