It sounds like you want something like this:
- $("#spinner")
- .ajaxStart(function(){
- var $spinner = $(this);
- $spinner.data("timer", setTimeout(function(){
- $spinner.show();
- }, 500));
- })
- .ajaxStop(function(){
- $(this).hide();
- clearTimeout($(this).data("timer"));
- });
That way you don't need to know which requests take a lot of time; if it takes more than half a second they'll see the spinner. I didn't test the code but hopefully it works and/or you get the idea.
If your requests use different progress indicators (e.g., different elements on the page) then yes, you'd need to show the specific indicator before doing a particular ajax and then hide it in the complete handler.