4

In Prototype, are there AJAX start/stop events that would allow you to create one script for globally displaying a modal wait message during AJAX loads?

Like, with jQuery I'm using this one script in the application layout to globally display a modal wait dialog for any jQuery AJAX events:

<script type="text/javascript">
$(document).ajaxStart(function () {
    $.blockUI({ message: '<h1><img src="../images/busy.gif" /> Just a moment...</h1>' });
});
$(document).ajaxStop(function () {
    $.unblockUI();
});
</script>

Thanks - much appreciated?

1 Answer 1

9

With Prototype you have access to a variable Ajax.activeRequestCount (more info here)

This contains, at any time, the amount of currently active AJAX requests (those created by Prototype, anyway), by monitoring their onCreate and onComplete events

EDIT

Untested but something like this should work:

Ajax.Responders.register({
  onCreate: showProcessing,
  onComplete: hideProcessing
});

function showProcessing() {
  if(Ajax.activeRequestCount > 0){
        $('inProgress').show();
    }
}

function hideProcessing () {
  if(Ajax.activeRequestCount <= 0){
      $('inProgress').hide();
  }
}
1
  • cool thanks - you wouldn't know of an example for monitoring that? Would it just be having a funtion running contantly checking for > 1 to display the wait and < 1 to clear the wait? Thanks!
    – Reno
    Mar 13, 2011 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.