None of the answers provided here on Stack Overflow would work for me. I'm using the latest and greatest FireFox for development and others here use IE, Chrome, etc.... Every time I made a call to jQuery's AJAX nothing would happen and ONLY when the AJAX call came back - would the cursor change. Then it would be stuck in the wait cursor. So - the call is made, the server returned the new information, the information was displayed and then WHAM! Wait cursor displays and won't go away. I tried ALL of the answers given. The .ajaxXXXX stuff were being called. (I put an ALERT("HERE"); into the functions and those "HERE"'s showed up all of the time. Every single call. Very depressing.
So I went "Ok - new stuff doesn't work. What about going old school?" I know it is clunky to do so - but this isn't some great big program I'm working on. It's just a little editor so several people can edit our database at the same time. Never going to see the light of the internet. Only the intranet. :-) Anyway, this works and works terrifically. You need to provide your own wait cursor. I just grabbed one off of Google Images to use.
First - the HTML:
<div id='wait' name='wait'
style='position:absolute;top:-9999px;left:-9999px;background-color:rgba(0,0,0,0.3);'>
<table border='0' cellspacing='0' cellpadding='0' style='width:100%;height:100%;'><tbody>
<tr><td style='width:100%;height:50%;'> </td></tr>
<tr><td align='center'><img id='cursor' name='cursor' src="images/wait.gif"></td></tr>
</tbody></table>
</div>
Then the jQuery:
function waitCursor()
{
$('#wait').css({
'top' : '0px',
'left' : '0px',
'width' : '100%',
'height' : '100%'
});
}
function defCursor()
{
$('#wait').css({
'top': '-9999px',
'left' : '-9999px',
'width' : '0%',
'height' : '0%'
});
and
$(document).ajaxStart(function(){ waitCursor(); })
.ajaxComplete(function(){ defCursor(); })
.ajaxStop(function(){ defCursor(); });
Old school but simple also. Just has a DIV with a table in it. The table has only to rows. The first one is 50% of the height of the entire screen. The second one simply centers the wait cursor on the screen. You could always make the height of the first one 45% or whatever half the height of the screen is minus half the height of the image. But as I said - this is just for a simple in-house program. The thing is - this works on all browsers without trying to jump through a lot of hoops to get it to show up. I've seen something similar on other major websites. So obviously others have gotten fed-up over the browsers not showing a wait cursor when needed and truth to tell - I remembered seeing this and wondered just how hard it would be to replicate. Now I know - it isn't hard at all.
Have fun!