linein designs

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:


Related Posts:
  1. Run Javascript Code After an AJAX Request
  2. Alternate Background Colors Using PHP

6 Comments »

Comment by Raine

Why do you use getElementById while you can use $(‘#text_box’).html(data)?

 
Comment by jeff

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

Comment by john

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.

 
Comment by Robby

You should just be able to specify “path/to/image.png” instead of “script.php”.

 
 
Comment by Alaki

how to download code ? or any demo ?

 
Comment by halfpipe

It was useful to me.! Thank you very much.! :]

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post



Please Support Our Sponsors

A Payday advance can be a great way to get back on track.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.