?
Solved

loading gif jquery

Posted on 2013-07-01
7
Medium Priority
?
414 Views
Last Modified: 2013-07-01
I have a php file, and at the top there is a select dropdown where a user chooses a client and then an ajax call is made to the db, however this can sometimes take up to 30 seconds depending on which client they chose.

what i want to do is have a lightbox affect with a loading gif to show that the report is being generated.

any and all help is gratefully appreciated...

thx
0
Comment
Question by:leozayas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 39291775
Is there a reason you need to use lightbox?  After all, the easiest way to do this would be just to place a div next to the dropdown with a loading .gif image with display set to none in your CSS.  Then you could use jQuery to simply add a show on click event and use a jquery hide in your AJAX upon completion.
0
 

Author Comment

by:leozayas
ID: 39291827
no there is no specific reason only to be more aesthetically pleasing and to stop any other input while the report is loaded....
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39291842
If you want to prevent access to the page while your AJAX request is running, you could always use a modal dialog from the jQuery UI library. It also includes a ProgressBar widget:

jqueryui.com/progressbar/
jqueryui.com/dialog/
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:leozayas
ID: 39291855
I added a div to the css file:

#loading-div { display:block; position: absolute; top: 50%; left: 50%; width: 100px; height: 100px; background-image: url(../reports/images/loading.gif); background-repeat: no-repeat; }

but it never shows.....firebug reported no problems and images is uploaded to server and in correct file

and here is the javascript:

$(document).ready(function() {
      $('#loading-div').hide();

      $('#campaign').change(function() {
            $('#loading-div').show();
            var theCampaign = $(this).val();
                  //alert(theCampaign);
            
        $.ajax({
            type: 'GET',
            url: '_get-main-report-data.php',
            data: 'theCampaign='+theCampaign,
            success: function (response) {
                        console.log(theCampaign);
                console.log(response);
                        $('#results').html('<img src="images/loading.gif" />')
                        $('#results').empty().append(response);
                        
                        $('#reportTable').dataTable({
                              aLengthMenu: [[10,25,50,100,150,200,300,400,800,1000,100000], ['10','25', '50', '100', '150', '200', '300', '400', '800','1000','100000']],
                        });
                        $('#loading-div').hide();
            }
        });
......
0
 

Author Comment

by:leozayas
ID: 39291857
chris, i like the progress bar widget, how would i set that to last until the query was done?
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39291894
You would create the dialog box and progress bar and then before your AJAX call you open the modal dialog. Once the AJAX call is complete, you close the dialog. Something along these lines:

//HTML
<button id="clicker">Open Dialog Box</button>
		
<div id="response">This is the response</div>
		
<div id="myDialog" title="Demo Modal Dialog">
	<div id="progressBar"></div>
	Please wait while we run the ajax code
</div>

Open in new window

//jQuery
$(document).ready(function() {
	//create the dialog box
	var myDialog =  $("#myDialog").dialog({
		modal: true,
		autoOpen: false
	});

	//create the progress bar
	$("#progressBar").progressbar({ value: false });

	$('#clicker').click(function() {
		//open the dialog
		myDialog.dialog("open");

		//make the AJAX call
		$.ajax({ url: "data.php" })
			.done(function(response) {
				//AJAX call is finished so update the DOM
				$('#response').html(response);
				//close the dialog box
				myDialog.dialog("close");
			});
	});
});

Open in new window

0
 

Author Closing Comment

by:leozayas
ID: 39291911
thanks chris :-)
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question