im trying to convert a json string from my .php file using eval() function but it doesnt work. the browser console says SyntaxError: expected expression, got '<'...
but when i comment out the line where eval() is, and use document.write(data); the string appears...
here's my code..
<html>
<head>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
var go = function() {
$.get("testjson.php", function(data) {
var obj = eval("(" + data + ")");
document.write(obj.name + "<br />");
document.write(obj.date + "<br />");
});
}
</script>
</head>
<body>
<input type='button' value='go' onclick='go()' />
<body>
</html>
and here's the code of my testjson.php file...
<?php
$msg = array(
"name"=>"hi there Victor!",
"date"=>"Monday 21st Feb 2010"
);
$myMsg = json_encode($msg);
echo $myMsg;
?>
im using latest version of jquery..