pass a variable from PHP to JavaScript -


this question has answer here:

i using json string pass variable in javascript 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, using following snippet :

console.log( result ) ;                 var json = eval('('+ result +')') ; 

and appears in console following error :

1{"data":[{"id":"1","alert_type_id":"1","deviation":null,"threshold_low":"20","threshold_high":"80"}]}  syntaxerror: expected token ')' 

could please me overcome issue please ? many thanks.

well line of code isn't valid.

write in console:

'(1{"data":[{"id":"1","alert_type_id":"1","deviation":null,"threshold_low":"20","threshold_high":"80"}]})' 

as you're passing eval function. should give same error.

if want save string in variable need adjust bit:

eval('var x =' + result); 

anyway looks you're doing wrong, check again why need ti use "evil" eval.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -