I have written a code which sends a query to mysql database and then gets the results row by row using $row = mysql_fetch_assoc($result).
I need to send the data for each row to a javascript function.
Here is the piece of code I used:
while($row = mysql_fetch_assoc($result))
{
echo '<script type="text/javascript">'.'queryResults('. json_encode($row) . ');'.'</script>';
}
In my javascript function I have :
function queryResults(data){
var results = JSON.parse(data);}
However, I get error:
"SyntaxError: JSON.parse: unexpected character"
Where is the problem with my code?
data? And do you really output tons of script tags?JSON.parsehere. Echoing JSON from PHP into JavaScript will just create an object literal in JavaScript.