Http://hi.baidu.com/mallor/blog/item/22a4dc1f9497a465f724e4e3.html
We often return a value in JSON format on the server side, which can be directly used as a complete object in the script. However, many new users usually encounter an error message: Invalid label, this problem is often distressing, because the correct JSON format is prompted with an error.
Assume that you return a JSON string from the server:
Javascript:
-
- {
- siteName : "CodeBit.cn",
- siteUrl : "http://www.CodeBit.cn"
- }
-
Run the following command in eval mode in the script:
Javascript:
-
- var result = eval(o.responseText);
- alert(result.siteName);
-
The following message is displayed:Error: Invalid label
In fact, our JSON format is not incorrect, but when Eval is used, you should enclose your JSON value in brackets:
Javascript:
-
- var result = eval("(" + o.responseText + ")");
- alert(result.siteName);
-
Haha, this is often the easiest to ignore, but once there is an error, it is also the most headache :)