2

I use jQuery to block ui like this

$('#send').click(function() {
       $.blockUI({ message: 
       '<p id="loading"><img src="images/busy.gif" /> processing...</p>'});  
        send();
       $(document).ajaxStop($.unblockUI); 
       setTimeout($.unblockUI, 2000); 

}); 

send() does some background processing and sets a response message in #loading tag. After the process is finished I want this message to stay for some seconds so I use the setTimeout but this does not work.

Any ideas?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

2 Answers2

2

Your script seems to call the unblockUI using ajaxStop already? Have you tried to remove this line or set your timeout within the ajaxStop handler?

UPDATE

You could try this:

$('#send').click(function() {
    $.blockUI({ message: '<p id="loading"><img src="images/busy.gif" /> processing...</p>'});  
    send();
    $(document).ajaxStop(function(){
        setTimeout($.unblockUI, 2000); 
    }); 
}); 
polarblau
  • 17,649
  • 7
  • 63
  • 84
  • but when I remove ajaxStop, the ui is unblocked no matter if the process is finished or not. how do I set the timeout within ajaxStop? – DarkLeafyGreen Jan 16 '11 at 19:39
0

You can use jQuery's delay([time in seconds]) function. As far as I know, setTimeout works on another workflow than the rest of the script.

linkyndy
  • 17,038
  • 20
  • 114
  • 194
  • Well, you append it to the queue of actions attached to a selector. For example, `$("#div").show().delay(2000).hide();`. The thing is, as I remember, that `delay()` is most suitable for effects; it is not a replacement for `setTimeout()`. Now, I don't know exactly whether it is suitable for what you intend to do or not. – linkyndy Jan 17 '11 at 11:59