![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
var data = eval('(' + req.responseText + ')'); |
#3
| |||
| |||
|
|
(...) You can go through this for detailed explanation:http://rayfd.wordpress.com/2007/03/28/why-wont-eval-eval-my-json-or-j... |
#4
| |||
| |||
|
|
var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. You can go through this for detailed explanation: http://rayfd.wordpress.com/2007/03/28/why-wont-eval-eval-my-json-or-json-object-object-literal/ Kiran Makam |
#5
| |||
| |||
|
|
Kiran Makam wrote: var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. You can go through this for detailed explanation: http://rayfd.wordpress.com/2007/03/28/why-wont-eval-eval-my-json-or-j... Kiran Makam Ahhhhh ... syntactic ambiguity. Why didn't you just say so? ô¿Ô¬ No wonder I couldn't figure it out for myself. So .... while I'm on this topic. I'm sending data back to an XMLHttpRequest from Php and not even using JSON. I merely use: ?php echo "var somevar1 = 'somevalue1';"; echo "var somevar2 = 'somevalue2';"; exit; ? Then I just "eval(req.responseText);" Is there any need for me to convert this to an object and use JSON instead when simply passing back a group of simple variables? |
#6
| |||
| |||
|
|
var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. |
#7
| |||
| |||
|
|
Kiran Makam wrote: var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. That ought to be in the FAQ under: http://jibbering.com/faq/#eval with a link to http://json.org/ Garrett |
#8
| |||
| |||
|
|
Kiran Makam wrote: var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. That ought to be in the FAQ under:http://jibbering.com/faq/#eval with a link tohttp://json.org/ |
#9
| |||
| |||
|
|
On Jul 3, 1:46 pm, Garrett Smith <dhtmlkitc... (AT) gmail (DOT) com> wrote: Kiran Makam wrote: var data = eval('(' + req.responseText + ')'); In JavaScript, "{" and "}" are used to denote - a block of code and - an object literal when you execute eval( "{'key':value}" ), "{" is executed as a block of code instead of an object literal. Hence inner parenthesis is used to force eval to treat the json-string as an object literal. That ought to be in the FAQ under:http://jibbering.com/faq/#eval with a link tohttp://json.org/ FAQ**TRY |
|
Peter |
![]() |
| Thread Tools | |
| Display Modes | |
| |