11-06-2007, 11:34 PM
|
#1 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
JSON invalid label
I feel it's important to reiterate a point I made in this article about JSON with PHP and Javascript. The Javascript error "invalid label" may be a tough one to overcome if you're blissfully unaware of why the error's being thrown.
JSON strings look something like the following:
Quote:
|
{"Juicy":"Grapes","Colourful":"Dragon Fruit"}
|
However, when feeding them in to eval, you must place parenthesis around them, so your JSON line looks like so:
PHP Code:
var szJson = '({"Juicy":"Grapes","Colourful":"Dragon Fruit"})';
In an AJAX function this would look like so:
PHP Code:
var szJson = eval('(' + pResponse.responseText + ')');
After that your JSON string will be more than ready to be run through Javascript's eval without any complaints!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|