I want to do some loop with javascript and get the problem. What do I need to get JSON results from the query:
device [1] .data.deviceTypeString.value devices [2] .data.deviceTypeString.value etc. Here is the code.
& lt; Script & gt; (Var x = 0; x & lt; 5; x ++) {$ .getJSON ('0', function (data) {var output = 'data.devices [' + x + '] .data.deviceTypeString.value ; 'Document .lib (output + "& lt; br / & gt;");}); } & Lt; / Script & gt; The problem is that I am not getting the result of JSON, I am getting the result of this:
data.devices [0] .data .deviceTypeString.value; Data.devices [1] .data.deviceTypeString.value; Data.devices [2] .data.deviceTypeString.value; Data.devices [3] .data.deviceTypeString.value; Data.devices [4] .data.deviceTypeString.value; Please help
change
var output = 'data.devices [' + X + '] .data.deviceTypeString.value;' with
var output = data.devices [x] .data.deviceTypeString.value; Do not read about javascript before using and pls document.write ..
jquery .
BTW You are using AJAX and it should be called sequentially in more than one JSO files .. But I think you need to call it once ... so:
$ GetJSON ('0', for function (data) {for (var x = 0; x & lt; 5; x ++) {var output = data.devices [x] .data.deviceTypeString.value, div = Document. CreateElement ('div'); div.textContent = output; document.body.appendChild (div);}}}); or
$ GetJSON ('0', function (data) {for (var x = 0, out = ''; x & lt; 5; X ++) {out + = data.devices [x] .data.deviceTypeString.value + '& Lt; br & gt;',} document.bird.innerHTML = out;});
Comments
Post a Comment