Jquery.post usage about type setup problem supplement

Source: Internet
Author: User
Tags eval json javascript eval

  When using AJAX to get data, direct Data.foo can be obtained. and the lower version of jquery is not a good example before 1.4, here is a brief introduction to the Jquery.post usage about the type Setup problem

  When using AJAX to get data, direct Data.foo can be obtained. and the lower version of jquery doesn't work. For example, before 1.4     code as follows: $.post ('/admin/userbookview.do ', {}, function (data) {  Console.info ( Data); });    Print the data information, displaying a JSON-formatted string with the following:  code: {"Acceptis": null, "entity": null, "Refuseis": NULL, ' result ': {' pageSize ':10,  ' resultlist ': [{' Price ': 3, ' wctime ': null, ' note ': ' Integral exception ', ' Cktime ': null, ' Cuser ': "Admin",  "CTIME": "2013/12/30 17:03:16", "PHONE": "13111050937", "ADDR": "Test Address", "Cuserid": "1", "Sltime": null}],   "Resultlistarray": null, "titles": ["ID", "CTIME", "state" "Price", "note"], "totalpage": 1, "TotalSize":4},  ' source ': null, ' Storageis ': null, ' TreeNodes ':null}    If no type is set, the default returned data is the text type     when we use data. To try to get the value inside, the return is undefined    Two solutions:    One: Use the Eval function to convert the JSON string to a JSON object   copy code code as follows: Var datas= Eval ("(" +data+) ");    Reference: Relationship between JavaScript eval and JSON     Two: Specify type   Copy code code as follows: $.post ('/admin/ Userbookview.do ', {}, function (data) {  CoNsole.info (data); }, "JSON");    high version such as 1.8+ does not have this problem, returns the JSON object    

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.