i trying display json data key value dynamic varies 1 post request data hierarchy shown in diagram:
this part of code running,can suggest me how display json data key showed in redbox gonna change every post request
$.ajax({ type: "post", url: "/", datatype:'json', data : { 'perfid': valueone, 'hostname': $("#host").val(), 'iteration': valuethree}, success: function(data) { $('#img1').hide(); var k = data[$("#host").val()].iscsi_lif.result.sectoutput.sect.length; for(var = 0; < k; i++) { var obj = k[i]; console.log(obj); var iscsi = parseint(data[$("#host").val()].iscsi_lif.result.sectoutput.sect.obj.avg_latency); console.log(iscsi); }
while running above snippet getting following error message :
data[$(....).val(...)].iscsi_lif.result.sectoutput.sect undefined
you can use "for in" loop iterate on keys of object without having specify key names.
for( var key in myobject){ myvalue = myobject[key]; // key dynamically created keyname }
so code similar following:
... success: function(data) { $('#img1').hide(); var obj = data[$("#host").val()].iscsi_lif.result.sectoutput.sect; for(var key in obj) { if(obj.hasownproperty(key)){ var iscsi = parseint(obj[key].avg_latency); console.log(iscsi); } } }
Comments
Post a Comment