A better loading message with Ext and jQuery
Posted by Steve Brownlee on December 19, 2007Dec 19
It couldn’t be easier to have an attractive loading message that actually prevents those click-happy users from firing off 20 AJAX requests because they didn’t know anything happened when they clicked that “Order Now” link.
Include the jQuery library, the core Ext functions and the dialog functions.
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/ext-core.js"></script>
<script type="text/javascript" src="js/ext-dialogs.js"></script>
Use the jQuery ajaxStart() and ajaxStop() methods to show a modal dialog that the user can’t mess with.
$(document).ready(function() {
dialog = new Ext.BasicDialog("loading", {
modal:true,
width:200,
height:100,
shadow:true,
collapsible:false,
draggable:false,
resizable:false,
closable:false
});
$("#loading")
.ajaxStart(function(){ dialog.show(); })
.ajaxStop(function(){ dialog.hide(); });
}
Lastly, a simple DIV with an animated gif and some text.
<div id="loading" style="display:none;">
<div class="x-dlg-hd">Processing...</div>
<div class="x-dlg-bd">
<div class="x-dlg-tab" title="">
<div class="inner-tab" style="font-size:1.25em; font-weight:800;"><img style="margin-right:15px;" src="images/loadingcolors.gif" border="0" />Please wait...</div>
</div>
</div>
</div>
Now when the user fires an event that requires an AJAX call, the dialog will immediately appear to prevent any further interaction with the site, and then disappear once the request is done.



-
Hi,
just disabling the “Order Now” (perhaps showing some additional ajax loading indicator) would have been better than to block the complete browser.
djot
-
djot, you need to see the forest through the trees. My simple example was exactly that, and certainly not what I’m using it for. My application needed this functionality and I’m sure others would find it useful
There’s also the blockUI jQuery plugin that one could use (http://www.malsup.com/jquery/block/).
Although this is a good example of another way to do it.
@Adam – yes I actually was using that plugin on the project previous to my current one. It works perfectly well, and I recommend it to others. The only reason I switched to my solution was so that I had a consistent look & feel with the other app dialogs.
Oh, and back to djot’s comment, my solution does not block the browser at all. Users can still interact with the browser, just not any of the UI elements on that page.
Hi,
is there any live example of the loading message when we click submit and content of the other page is loading