JS handles the JSON "invalid label" error

Source: Internet
Author: User

JSON is a convenient data transmission method when you use Ajax.
However, for many people, the "invalid label" error is a very troublesome problem. It seems that the JSON string is correct. How can this problem be solved?

For exampleCode:

 
  
  
  1. Function Handle_success(Response){
  2. VaRJSON= Eval(Response); // Response = "{'foo': 'bar '}";
  3. }

The browser will report that invalid label is incorrect because Eval will try to interpret your response as a label. When you directly write in the script:

 
  
  
  1. <Script>
  2. {'Foo' : 'Bar'};
  3. </Script>

The principle of the error is the same.

There are two solutions:

 
  
  
  1. VaRJSON= Eval('(' +Response+ ')'); // Response = "{'foo': 'bar '}";
  2.  

Or

 
  
  
  1. Eval('Var JSON =' +Response); // Response = "{'foo': 'bar '}";
  2. // JSON is available now
  3.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.