Question about setting type in jquery. post usage

Source: Internet
Author: User

Question about setting type in jquery. post usage

This article mainly introduces the type setting of jquery. post usage. For more information, see

When ajax is used to obtain data, data. foo can be obtained directly. The earlier versions of jquery won't work, for example, before 1.4.

The Code is as follows:

$. Post ('/admin/UserBookView. do', {}, function (data ){

Console.info (data );

});

 

Print the data information and display a json string, as shown below:

The Code is as follows:

{"AcceptIs": null, "entity": null, "refuseIs": null, "result": {"pageSize": 10,

"ResultList": [{"PRICE": 3, "WCTIME": null, "NOTE": "Point exception", "CKTIME": null, "CUSER ": "admin ",

"CTIME": "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 data returned by default is of the text type.

 

When we use data. To obtain the value, the returned value is undefined.

 

There are two solutions:

 

I. Use the eval function to convert a json string to a json object.

The Code is as follows:

Var datas = eval ("(" + data + ")");

 

Ii. specify the type

The Code is as follows:

$. Post ('/admin/UserBookView. do', {}, function (data ){

Console.info (data );

}, "Json ");

 

If the version is later than 1.8, this problem does not occur. The returned result is a 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.