Prototype - Are there AJAX start/stop events to global trigger an AJAX modal wait message?
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?
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();
}
}
精彩评论