I am new to both HTML and Javascript, but I have a problem when I try to create a dynamic page. I have to update the tags on the webpage, getting rows from the JSON database every 5 seconds. My code looks something like this:
HTML:
<label id="tag1">0</label>
JavaScript:
$(document).ready(function(){
$.ajaxSetup({ cache: false });
setInterval(function() {
$.getJSON("js/database.json",function(data){
if (data.tag1 == true) {
$('#tag1').text(data.tag1);
}
});
},5000);
});
This part that I put after all the blocks <body>
JSON:
{
"database": [
{
"tag1": ""
},
{
"tag2": ""
},
{
"tag3": ""
},
{
"tag4": ""
},
{
"tag5": ""
},
{
"tag6": ""
}
]
}
Does anyone know what the problem is? The webpage does not update id1 at all.
Thanks in advance.
source
share