Type setting for jquery. Post usage
- 2020-03-30 02:06:50
- OfStack
When you use ajax to fetch data, you can get it directly from data.foo. The lower version of jquery doesn't work like before 1.4
Print the data information and display the string in json format, as follows:
If type is not set, the default data returned is of type text
When we use data. To try to get the value inside, we return undefined
Here are two solutions:
One: use the eval function to convert a json string into a json object
Two: specify type
Higher versions such as 1.8+ do not have this problem and return json objects
$.post('/admin/UserBookView.do', {}, function(data) {
console.info(data);
});
Print the data information and display the string in json format, as follows:
{"acceptIs":null,"entity":null,"refuseIs":null,"result":{"pageSize":10,
"resultList":[{"PRICE":3,"WCTIME":null,"NOTE":" Integral anomaly ","CKTIME":null,"CUSER":"admin",
"CTIME":"2013/12/30 17:03:16","PHONE":"13111050937","ADDR":" Address of the test ","CUSERID":"1","SLTIME":null}],
"resultListArray":null,"titles":["ID","CTIME","STATE""PRICE","NOTE"],"totalPage":1,"totalSize":4},
"source":null,"storageIs":null,"treeNodes":null}
If type is not set, the default data returned is of type text
When we use data. To try to get the value inside, we return undefined
Here are two solutions:
One: use the eval function to convert a json string into a json object
var datas=eval("("+data+")");
Two: specify type
$.post('/admin/UserBookView.do', {}, function(data) {
console.info(data);
},"json");
Higher versions such as 1.8+ do not have this problem and return json objects