Stop auto refresh

Stop auto refresh

Hi All,

I'm a newbie of JQuery, and tried to design a script to auto refresh and stop it until there is a value returned which I'm looking at. I found a useful codes in Internet and below is the link

http://www.brightcherry.co.uk/scribbles/2009/02/26/jquery-auto-refresh-div-every-x-seconds/

I can start the auto refresh now, but still don't know how to stop it. Seems the codes used the paramter "data" to control should it be stopped or not. But I don't know how to control this parameter, can anyone teach me? Thanks

// Global Variables
var refreshId;

$(document).ready(
function() {
// Initial page load
$(“#responsecontainer”).load(“/test/test.php”);


// Start refesh counter
refreshId = setInterval(
function() {
// This function works with $.get
function doSomethingWithData(data) {
if (data != “pending”) {
// Reload & Display
$(“#responsecontainer”).load(‘/test/test.php?randval=’+ Math.random());
} else {
// Display
document.getElementById(‘responsecontainer’).innerHTML = “Done”;









// Stop refresh counter
clearTimeout(refreshId);
}
}
// Second refresh
$.get(‘/test/test.php?randval=’+ Math.random(), doSomethingWithData);
}
, 10000); // Time between refeshes 1000 miliseconds = 1 second
}
);