13 Nov, 2008
jQuery Loading – Display Images or Text Until Script is Finished
Posted by: john In: javascript| php| programing
I’m just finishing up a little project to improve the search ability on a website and I want to display an image and message say “loading…” until the script finished running. Below is an easy way to do that.
First just make sure you have the latest version of jQuery.
loading...
Now let’s see what all is going on.
First we’re calling jQuery’s ready() event which “binds a function to be executed whenever the DOM is ready to be traversed and manipulated.” (basically allows us to run any thing within the function after the page has completely loaded)
Next we’re using the get Ajax function to call the “script.php” page along with a variable to access in the “script.php”.
Once that script has finished running, we replace what was inside the “text_box” DIV with the response from the “script.php” file.
You can do any kind of script within the ready() function. The basic idea is have a DIV preloaded with the text or image and have jQuery replace what’s inside the DIV when it’s finished running.
I’m sure there are other ways to do this from with jQuery, so please share if you have a different way of doing this.
BTW: If you’re looking for a sweet AJAX loading GIF, check out www.ajaxload.info.
Similar Posts:
- jQuery Image Gallery with Transitions and Navigation
- Fade In and Out Images from a Single Directory Using jQuery (with plugin)
- Display Last.fm’s Recent Tracks on Web Site with PHP Function
- MySQL Return Single Data or Single Array with PHP
- Run Javascript Code After an AJAX Request
Related Posts:
loading...
January 7th, 2009 @ 8:36 pm
Why do you use getElementById while you can use $(‘#text_box’).html(data)?
March 20th, 2009 @ 3:28 pm
HI
thanks for sharing the jQuery Loading – Display Images or Text Until Script is Finished script.
I have a question :
1. how can I load and image instead of a script.php
2. If I can do the above, how can I call the function as many time as I need . (say I have a page the has many images to show, so I would like to display the loading-image and message for each image.)
thanks .jeff
March 20th, 2009 @ 11:09 pm
The above script is not what you need to use. Try the other post that loads and displays images from a single directory. I think it will start you off in the right direction.
http://linein.org/blog/2008/01/10/roate-image-using-jquery-with-plugin/
Another option would be to combine the two and have the above script load “script.php”. And then from within the “script.php” display the images from within a directory.
May 13th, 2009 @ 8:50 am
You should just be able to specify “path/to/image.png” instead of “script.php”.
May 22nd, 2009 @ 7:19 am
how to download code ? or any demo ?
July 12th, 2009 @ 5:15 pm
It was useful to me.! Thank you very much.! :]