How to evaluate json member using variable ?
Posted
by Miftah
on Stack Overflow
See other posts from Stack Overflow
or by Miftah
Published on 2010-04-29T10:06:39Z
Indexed on
2010/04/29
10:47 UTC
Read the original article
Hit count: 172
Hi i've got a problem evaluating json. My goal is to insert json member value to a function variable, take a look at this
function func_load_session(svar){
var id = '';
$.getJSON('data/session.php?load='+svar, function(json){
eval('id = json.'+svar);
});
return id;
}
this code i load session from php file that i've store beforehand. i store that session variable using dynamic var.
<?php
/*
* format ?var=[nama_var]&val=[nilai_nama_var]
*/
$var = $_GET['var'];
$val = $_GET['val'];
$load = $_GET['load'];
session_start();
if($var){
$_SESSION["$var"] = $val;
echo "Store SESSION[\"$var\"] = '".$_SESSION["$var"]."'";
}else if($load){
echo $_SESSION["$load"];
}
?>
using firebug, i get expected response but i also received error
uncaught exception: Syntax error, unrecognized expression: )
pointing at this
eval('id = json.'+svar);
i wonder how to solve this
© Stack Overflow or respective owner