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

})
3
  • This might help: stackoverflow.com/questions/13869627/…. You will have to use item["host_detail.site"] Can you share a sample JSON as well? Commented Sep 22, 2016 at 7:11
  • 1
    Is host_detail.site key of the object or you have nested object ? Commented Sep 22, 2016 at 7:14
  • Hi Rajesh, yes item["host_detail.site"] solve my pro. Thank YOu very much Commented Sep 22, 2016 at 7:22

1 Answer 1

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>");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.