Skip to main content

jQuery doesn"t .load() until .ajax() within callback of .load() is complete?



My problem is that the <div> with the jQuery progress bar ( dnc_scrubber.html ) isn't loaded until all of the other requests are complete.





Is there anyway around this? I want to change the content of #tabs-1 to the progress bar, and animate it while dnc_scrubber.php is doing its work.





The lines.php and progress.php files are used to calculate the percentage of work done by dnc_scrubber.php - which updates the session as it goes along. lines.php and files.php return the session variable.







$('#tabs-1').load('dnc_scrubber.html', function() {

var querystring = 'col=' + col + '&' + makeQS(files);

var lines = 0;



$('#progressbar').progressbar();



$.ajax({

url: 'dnc_scrubber.php',

type: 'POST',

async: true,

data: querystring,

complete: function() {

for (i = 0; i < files.length; i++) {

$('#complete').append('<a href="process/MATCHED - ' + files[i] + '">MATCHED - ' + files[i] + '</a><br />');

$('#complete').append('<a href="process/SCRUBBED - ' + files[i] + '">SCRUBBED - ' + files[i] + '</a><br />');

}

}

});



$.ajax({

url: 'lines.php',

async: true,

dataType: 'json',

complete: function(json) {

lines = json.total;

}

});





function setProgress() {

if (prog < lines) {

prog = getProgress();

$('#progressbar').progressbar('option', 'value', prog);

setTimeout(setProgress(), 1000)

} else {

$('#progressbar').progressbar('option', 'value', 100);

}

}



var prog = getProgress();

setTimeout(setProgress(), 1000);

});







I have already tried loading the progress bar within the callback function of a .ajax() request with async set to false . The same result happens - the progress bar is not loaded into #tabs-1 until dnc_scrubber.php is complete.





What can I do?


Comments

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.