1

My JSON return object is like following. I try to append a table with jquery and it work well if the data is like item.district, but error prompt if it`s like item.host_detail.site(2 "dot").

Thank For help in advance.

Object
district:"KUCHING"
host_detail.HostID:"41"
host_detail.site:"SIMONTESTING"
ipaddress:"10.17.102.169"
log_detail.task:"Auto-Backup"


$.each(data, function(i, item){ 

$("#tabledisplay > tbody").append("<tr><td>" + item.host_detail.site + "</td><td>" + item.district + "</td></tr>");

})
user647527
  • 289
  • 2
  • 3
  • 15
  • This might help: http://stackoverflow.com/questions/13869627/unable-to-access-json-property-with-dash. You will have to use `item["host_detail.site"]` Can you share a sample JSON as well? – Rajesh Sep 22 '16 at 07:11
  • 1
    Is `host_detail.site` key of the object or you have nested `object` ? – Rayon Sep 22 '16 at 07:14
  • Hi Rajesh, yes item["host_detail.site"] solve my pro. Thank YOu very much – user647527 Sep 22 '16 at 07:22

1 Answers1

2

assuming

var item = {district:"KUCHING",host_detail:{HostID:"41",site:"SIMONTESTING"},ipaddress:"10.17.102.169",log_detail:{task:"Auto-Backup"}}

then you need to remove the loop:

$("#tabledisplay > tbody").append("<tr><td>" + item.host_detail.site + "</td><td>" + item.district + "</td></tr>");
madalinivascu
  • 32,064
  • 4
  • 39
  • 55