Question

window.onload = setupRefresh;
function setupRefresh() {
    setInterval("refreshBlock();", 1000);
}

function refreshBlock() {

    $('#activeItems').load("current_auctions.php");

}

the above code automatically refreshes the content of a div tag on my page every 1 second.

window.onload = setupRefresh;
function setupRefresh() {
    setInterval("refreshBlock();", 1000);
}

function refreshBlock() {
    if ($('#myAccount').html() == 'My Accout') {
        $('#activeItems').load("current_auctions.php");
    };
}

The above code, which only has the addition of an if statement, loads up the page once in the beginning, and then ceases to refresh. How can I fix this code?

Était-ce utile?

La solution

Probably because that conditional is returning false.

if ($('#myAccount').html() == 'My Accout') {

Quite likely because of the typo in 'Accout', as @nnnnn says.

You can debug this quite easily in Chrome or Firefox by using a script terminal. In Firefox you could install Firebug or in Chrome just press Crtl+Shift+J. Either way get to a JavaScript command-line interface and enter:

$('#myAccount').html() == 'My Accout'

In your page. You'll see it return either true or false. If it's false you can then easily tweak that condition until it's true where you're expecting.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top