Jquery. Post usage complements the type setting problem

  • 2020-03-30 01:13:14
  • OfStack

Jquery. Post usage (link: #)
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
$.post('/admin/UserBookView.do', {}, function(data) { 

Print the data information and display the string in json format, as follows:
"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}], 

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+")"); 

Reference: (link: #)

Two: specify type
$.post('/admin/UserBookView.do', {}, function(data) { 

Higher versions such as 1.8+ do not have this problem and return json objects

Related articles: