JS eval () method to process JSON strings

Source: Internet
Author: User

PHP Code snippet:

Public Function Demo () {$sql = ' select count (0) from table where id= '. $id;        if (! $mysql->getresult ($sql)) {echo json_encode (Array (' Code ' = 2));    Exit } Echo Json_encode (' code ' + 1, ' mes ' = ' Are you sure you want to change the Tablez information?    ‘)); Exit;}

jquery Code Snippet:

 $ ("#info_btn"). Click (function () {    $.get ('/dmeo?_t= '  + math.random (),  function (data) {            var jsondata =eval ("(" + data + ")");         //here eval () processing the JSON string why use two parentheses?         if (jsondata.code==1)  {             if (Confirm (jsondata.mes)) {                 $ ("#Table_info"). Show ();                 $ ("#Form_info"). Hide ();             }        }         if (jsondata.code==2)  {              $ ("#Table_info"). Show ();             $ ("Form _info "). Hide ();         }    });

The

JS eval () method processes the JSON string

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.