I am using jQuery to load a massive table in batches of rows. I am loading the initial rows, then I make $.ajax calls to append rows to the body of the table. On completion of the insertion of the next chunk of rows, I call the method to process the next chunk of rows. See code below. The problem is, even after all the content is loaded, the javascript still claims to be executing - when I go to navigate to another page is complains that there is a javascript routine slowing down the page and do I want to abort it. At this point, it shouldn't be running! This routine is initially called from the $(function() {...}) routine (on ready). Any ideas how I am supposed to stop this from continuing after it has completed all it's work?
function processNextChunk(c, t, s, p, x) {
var args = "{company_ID:" + c + ",shareholdingType:" + t + ",startIndex:" + s + ",pageSize:" + p + ",stack:'" + x + "'}";
//alert(args);
$.ajax({
type: "POST",
url: "TestStructure6.aspx/GetNextHierarchyPage",
data: args,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
//Append the content to the bottom of the table tag.
//Returning 2 arguments from the result, hence the split (initial
//value is an int, so not a big deal using pipe as a delimiter)
if (msg.d.length > 0) {
var slash = msg.d.indexOf('|');
var r;
if (slash > 0) {
x = msg.d.substr(0, slash);
r = msg.d.substr(slash + 1, msg.d.length - slash);
$('#h > tbody').append(r);
if (r.length > 0) {
var percent = (s + p) / totalRows * 100;
$('#counter').html(parseInt(percent) + '%');
setTimeout('processNextChunk(' + c + ', ' + t + ', ' + (s + p) + ', ' + p + ', "' + x + '")', 0);
//processNextChunk(c, t, s + p, p, x)
}
else {
$('#counter').html('');
}
}
}
return true;
}
});
return true;
}