I have a AJAX script which i was using previously and was able to retrieve data from viewCommentsJson.php as such[{"comments":"Greta"},{"comments":"John"}]. I was wondering if its able to decode the return value such that it display it properly ?
Thanks in advance
Greta
John
Main.php
<a onclick="showUser('.$row['ID'].')" method = "POST" action= "viewCommentsJson.php">Show Comments</a> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("Post","viewCommentsJson.php?q="+str,true); xmlhttp.send(); } </script> viewCommentsJson.php
$com = $_REQUEST["q"]; include 'connectDatabase.php'; //opening sql table $selected = mysql_select_db("2000",$dbhandle) or die("Could not select 2000"); $arr = array(); $data = mysql_query("SELECT comments FROM comment WHERE ID = '$com'"); $rows = array(); while($r = mysql_fetch_assoc($data)) { $rows[] = $r; } print json_encode($rows);