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.