linein designs

12 May, 2010

jQuery AJAX Loading – Display Images or Text Until Script is Finished (Part 2)

Posted by: john In: jquery|php|programing|tutorial

This is a more practical way to display an image or text while an AJAX request is loading.

DEMO | DOWNLOAD FILES

What we’re basically doing is forcing a DIV to have a starting image and then replacing it with the text return from the AJAX request.

function loadingAjax(div_id)
{
	$("#"+div_id).html(' saving...');
	$.ajax({
		type: "POST",
		url: "script.php",
		data: "name=John&id=28",
		success: function(msg){
			$("#"+div_id).html(msg);
		}
	});
}

Usage

save page

As always – if you’re looking for a sweet AJAX loading image, check out www.ajaxload.info..

If you have any questions or *gasp* improvements, please leave me a comment below.

Similar Posts:

6 Comments »

Comment by Superman

Hi

This is really helpful tut. I need some modifications about which I want to know that how can I do it? I want that images load as page loads. For example you can see this here at http://www.classiccars.co.uk there is two rows below of images where you can see the cars. How can I load images like that.

Regards

 
Comment by john

You could do something similar by replacing the image on a mouseover. First display the first image with something like this:



// then use jquery to replace the image for that id on a mouseover or click

 
Comment by Hasan

Thanks a lot. Surfing this from this morn.
Got it.. Thank u very much :)

 
Comment by wadebatyu

hi john… thank’s you for your solution…
but i have a little problem…

what i use command if i wanna run this script after load not click

thx very much

 
Comment by john

please use the contact form to email me. i’m not sure what you’re asking.

 
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


  • Seren: Thanks - google did not fail me in finding this snippet (after 2 hours of 'why isn't this working!' before I choose to look for answers. That select
  • zdenis: type your scp command with nohup at the beginning: >nohup scp... enter your password stop temporarily the command with CTRL+z put on b
  • Criz: php script >> How to get the number of hours and minutes of a two set of time like this sample. 1st set of time : 8:00 to 17:00 2nd set of


Please Support Our Friends

Banner
FreshBooks

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.