alejandro52 Posted September 27, 2010 Share Posted September 27, 2010 I want to return an array using ajax to javascript. if(xmlhttpmail.status ==200){ myarray = xmlhttpmail.responseText; for(i=0;i<10;i++){ document.getElementById("mylabel").innerHTML += myarray[1];; } }else{ document.getElementById("mylabel").innerHTML=xmlhttpmail.status; } if(isset($_GET["id"])){$id=$_GET["id"];$sql="SELECT * FROM keimena WHERE keim_id = '".$id."'";$result = mysql_query($sql);$num = mysql_num_rows($result);$row = mysql_fetch_array($result);if($num == 1){ echo $row;}else{ echo false;}} As you can see i awant to return an array but it doesn't return anything. Quote Link to comment https://forums.phpfreaks.com/topic/214520-return-array/ Share on other sites More sharing options...
trq Posted September 27, 2010 Share Posted September 27, 2010 You can't echo an array. Instead, send it as a json object which can easily be used by Javascript. json_encode Quote Link to comment https://forums.phpfreaks.com/topic/214520-return-array/#findComment-1116253 Share on other sites More sharing options...
alejandro52 Posted September 27, 2010 Author Share Posted September 27, 2010 how do i send a json oject in my exapmle? Quote Link to comment https://forums.phpfreaks.com/topic/214520-return-array/#findComment-1116255 Share on other sites More sharing options...
trq Posted September 27, 2010 Share Posted September 27, 2010 echo json_encode($row); Quote Link to comment https://forums.phpfreaks.com/topic/214520-return-array/#findComment-1116259 Share on other sites More sharing options...
alejandro52 Posted September 27, 2010 Author Share Posted September 27, 2010 I can't see how this works. First of all i need to return utf8 characters and that doesn't work. How am i going to send back an array from php to javascript Quote Link to comment https://forums.phpfreaks.com/topic/214520-return-array/#findComment-1116328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.