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. 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 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? 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); 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 Link to comment https://forums.phpfreaks.com/topic/214520-return-array/#findComment-1116328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.