jquery - How to loop over elements in a json list Ajax/Javascript -
i have issue ajax can see data i've given flask, doesn't seem parsing inside when loop it. 1 item loop, more when data fed it.
json string is:
{ "routers" : {"dnsrootserver": {"os": "4.4.4.4", "name": "dnsrootserver"}}}
so understands data.routers, , understands data.routers.dnsrootserver.name (as you'll see in console.log), when use loop on data.routers, looped item displays (el), seems fail when try el.name, saying it's undefined. javascript below:
$(document).ready(function(){ $.ajax({ url: "{{ url_for('.gui_form') }}", datatype: 'json', success: function(data, textstatus, xhr){ console.log(data) $(data.routers).each(function(i, el) { console.log(el) console.log(el.os) console.log(data.routers.dnsrootserver.os) var listem = "<br>" + el.name; $("#routers").append("<li>" + listem + "</li>"); }); } }); });
i've expanded console log can see data there , how looped el.os comes out undefined data.routers.dnsrootserver.name comes out cleanly ios:
object {routers: object}routers: objectdnsrootserver: objectip: "4.4.4.4"name: "dnsrootserver"os: "ios"__proto__: object__proto__: object__proto__: object object {dnsrootserver: object}dnsrootserver: objectip: "4.4.4.4"name: "dnsrootserver"os: "ios"__proto__: object__proto__: object undefined ios
any ideas i'm doing wrong?
based on javascript json shoud { "routers" :[ {"os": "4.4.4.4", "name": "dnsrootserver"}]}
Comments
Post a Comment