I have a page laid out with 2 Div’s on the page. The first Div works fine and loads a list of players. Now when you click on a link in that Div, it loads a second Div with information about that player. That too works fine, but what I want to do is have that second Div periodically refresh that players data after it being loaded by the click event. Here was my current attempt but it’s not working:
var loc = "";
$("a").live('click', function() {
loc = "player.php?user=" + $(this).html();
$("#result").load(loc);
});
setInterval(function() {
$("#results").load(loc);
}, 1000);
Try moving the
setIntervalinside theclickevent handler so that it doesn’t fire off before the first click and you ensure thelocis defined before the first interval completes.Also, you may have a typo within your
setInterval, as it refers to$('#results'), not$('#result'). One or the other is likely incorrect.Finally, it’s good practice to assign a
setIntervalto a variable, so that you can clear it later, if needed withclearInterval. it also lets you set the interval just once, rather than every time the user clicks