hi i have json array that i want to show every 5 second the next value
this code get the json from server and send json array to the function:
function myFunction() {
$.ajax({
type: "POST",
url: "ws.aspx/GetQueue",
data: "{'eventid':'" + eventID + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg != null) {
var obj;
if (msg.hasOwnProperty("d"))
obj = jQuery.parseJSON(msg.d);
else
obj = jQuery.parseJSON(msg);
setHtml(obj);
}
setTimeout(function () { myFunction(); }, 5000);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
setTimeout(function () { myFunction(); }, 5000);
}
});
}
this is my function after sent the array to it:
function setHtml(obj) {
for (var i = 0; i < obj.length; i++)
setTimeout(function () { $('.Summary').html("<H1>" + obj[i].QueueName + "->" + obj[i].name + ' : ' + obj[i].Queue + "</H1><br/>"); }, 5000);
}
but the values inside the loop are undifined , why is it?
what is the solution for this issue?
thanks, all are the answer except wirey for handle the json value inside loop.
the full answer is to add the element to queue like in this code: