I am using a JSON string to pass a variable in JavaScript from PHP :
while( $row = mysql_fetch_array($result) )
{
$tmp = array('id'=>$row['id'], 'alert_type_id'=>$row['alert_type_id'], 'deviation'=>$row['deviation'], 'threshold_low'=>$row['threshold_low'], 'threshold_high'=>$row['threshold_high']) ;
$settings[] = $tmp ;
}
echo '{"data":'.json_encode($settings).'}' ;
in Javascript, i am using the following snippet :
console.log( result ) ;
var json = eval('('+ result +')') ;
and what appears in the Console is the following error :
1{"data":[{"id":"1","alert_type_id":"1","deviation":null,"threshold_low":"20","threshold_high":"80"}]}
SyntaxError: Expected token ')'
Could you please help me overcome this issue please ?
Many Thanks.
Well that line of code isn’t valid.
Write in the console:
As this is what you’re passing to the
evalfunction. I should give you the same error.If you want to save that string in a variable you need to adjust it a bit:
Anyway It looks like you’re doing something wrong, check again why do you need ti use the “evil”
eval.