I want to get a json array from ajax call and store it in a array . I tried this code but it doest not work .The alert shows me the string {"value":[1]},{"value":[2]} .I need this string to be converted in JSON array and stored in myData .Is there any problem about the responseJSON or any other thing ? Plz help
making a call
setInterval(function showUser(str) {
str="1";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
var myData=(xmlhttp.responseJSON);
window.alert(myData);
}
xmlhttp.open("GET","new.php?q="+str,true);
xmlhttp.send();
}, 1000)
and this is the code for new.php
<?php
$conn =mysql_connect("localhost","root","") or die ("we couldn't connect!");
mysql_select_db("webauth");
$rs = mysql_query("SELECT * FROM test") or die(mysql_error());
while($row = mysql_fetch_array($rs))
{
echo '"{values":['.$row['value'].']}'.',';
}
}
?>
</div>