views:

183

answers:

5

The scenario is like: I'm using Jquery to implement some ajax features. For example: when a user click a button "get data", Jquery will call .ajax function to fetch some data from the server. This process might take some time, so I added .ajaxSend and .ajaxComplete functions to show some animation for the waiting process (actually a 'Loading Data' gif inside a div with z-index: 999 to be the top of other divs inside the ). During the waiting process (the 'Loading Data'), I would like to prevent users to click other buttons (for example: I have other tabs, buttons below the small 'Loading Data' gif). The way I achieved this is by:

    $("body").ajaxSend(function()
     {
        $(this).append('<div id="loading">Data Loading<\/div>');
        $("div#error").remove();
        $(this).children().not('#loading').css({'opacity':0.22});   
     });
    $("body").ajaxComplete(function()
     {
        $("div#loading").remove();
        $(this).children().not('#loading').css({'opacity':1});
     });

However, I don't think changing the opacity is the best way. Unless you make the opacity to 0, users can still click on other buttons/tabs. I don't know how to totally avoid any user interactions during this process? Thanks!!

+2  A: 

Use an overlay.

http://jqueryui.com/demos/dialog/#modal

Vinodh Ramasubramanian
actually, I'm using JqueryUI as well. Yes, I just tried dialog's modal option. It's easy to achieve the block effect I want. However, is there someway to remove the cross-over (close button) on the top-right corner of the dialog?
WilliamLou
See this http://stackoverflow.com/questions/896777/remove-close-button-on-jqueryui-dialog
Vinodh Ramasubramanian
thanks. I chose this as my answer since I already used JqueryUI so that I don't have to import another plugin only for blockUI effect
WilliamLou
+1  A: 

Make visible a div with a z-index above anything else. onsucess, hide it.

For IE6, consider visibility of select inputs

Alfabravo
I wish I could upvote (but I'm out for the next few hours), especially for warning of IE6 and form elements.
Jonathan Sampson
+5  A: 

I've used jQuery Block UI with good success in the past. Works well with Ajax:

http://malsup.com/jquery/block/

May be worth using a plugin such as this, rather than handcoding a similar solution...

KP
well, this plugin works well for this purpose, but I don't want to import too many plugins at this stage. Thanks, anyway. If I can't find a easier solution, I may turn to BlockUI later.
WilliamLou
A: 

See the answers to CSS/JavaScript Use Div to grey out section of page.

dacracot
A: 

I use a variant on Ben Nadel's ajax pipeline. Essentially he wraps the jQuery $.ajax call with an object that can record outgoing ajax requests.

When an ajax request goes out, you record the request name. If any more requests attempt to go out with the same name, you don't execute it (optionally providing a message to the user).

womp