my updated full script:
$(document).ready(function() {
$.getJSON('table.json',function(data){
$('#mytable').empty();
var html = '';
html += '<tr class="tableheader"><th>Name</th><th>Code</th><th>Value</th><th>Bid</th><th>Offer</th></tr>';
for (var i=0, size=data.length; i<size;i++) {
html += '<tr class="tablecontent"><td>'+ data[i].name+ '</td><td>'+ data[i].code+ '</td><td>'
+ data[i].value+ '</td><td>'
+data[i].bid+'</td><td>'+data[i].offer+'</td></tr>';
}
$('#mytable').append(html);
tablerows('mytable');
setTimeout(poll,5000);
});
});
var poll = setInterval(function(){
$.ajax({
type:"GET",
url: "dummy.json",
success: function(data){
//HANDLE DATA
setTimeout(poll,5000);
}
});
},5000);
Please help me in this. i have 3 JSONs. 1st Json will load initially. That is done.
2nd json needs to be parsed (which has 2 field changes) and show the initial json + changed fields and then again from 3rd JSON.
I have written below script:
var poll = setInterval(function(){
$.ajax({
type:"GET",
url: "dummy.json",
success: function(data){
//HANDLE DATA
JSON.parse(data);
}
});
},5000)
dummy.json is my second changed JSON. Is this the correct way?how should i call this function function in my $(document).ready?
Set it as a regular function and then call it from itself within the success handler so then you are never getting ahead of yourself. Then you can also just call it once from your $(document).ready.