Posts: 3,155
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
If I understand you correctly:
Make a variable called "loading" that is set to false, but is made true on click, but made false again in the callback. Then, in the click event, only make the AJAX call and fadeOut() if !loading:
Code:
loadingimg = '<img src="images/loading.gif" alt="Loading.." style="margin:auto;display:block;padding:15px;" />';
$(document).ready(function(){
var loading=false;
$('#rstory').html(loadingimg).load('ajax/randomstory.php', function() {
$('#rstory').fadeIn('fast')
});
$('#getrstory').click(function() {
if(!loading) {
loading=true;
$('#rstory').fadeOut('fast', function() {
$('#rstoryload').html(loadingimg)
$('#rstory').load('ajax/randomstory.php', function() {
loading=false;
$('#rstoryload').html('');
$('#rstory').fadeIn('fast');
});
});
}
});
});
|