I’m trying to refresh several sections of a page every 10 seconds or so with data being pulled from a php file. I think I’m close but I’m getting this error: ReferenceError: Can’t find variable: a
here is what I have so far:
//php
$a = "some a data...";
$b = "some b data...";
$c = "some c data...";
$data['a'] = $a;
$data['b'] = $b;
$data['c'] = $c;
echo json_encode($data);
//index
<script type="text/javascript">
$(document).ready(function() {
function loadPage(){
$.getJSON('roster.php', function(data) {
var a = data.a;
var b = data.b;
var c = data.c;
});
alert("a: "+a);// for testing
alert("b: "+b);// for testing
alert("c: "+c);// for testing
jQuery('#div-a').html(a);
jQuery('#div-b').html(b);
jQuery('#div-c').html(c);
}
loadPage(); // This will run on page load
setInterval(function(){
loadPage() // this will run after every 5 seconds
}, 8000);
}); //ready(function
</script
<div id="div-a"></div>
<div id="div-b"></div>
<div id="div-c"></div>
any idea?
Thanks,
aaron