Upload content and preload images via AJAX?

Say I like:

$(function() { $('a').click(function(e) { e.preventDefault(); var h = $(this).attr('href'); $('#content').load(h); }); }); 

It doesn’t actually download images, it just downloads content, how do you also download actual images?

Some people didn’t seem to understand: I mean that it downloads images, but it doesn’t “preload”, which means that you are watching the images load separately.

Change Let's say that href was equal to somepage.html, and on this page there were images on it, as well as content, yes, it downloaded images and content, but didn’t actually download images at all, you are still witnessing the loading of images separately . How to preload images in the request itself?

+4
source share
2 answers

Try the following:

  • Hide the div #content and call load on it. This will load the content invisibly so that your users do not see the image download after that.
  • Binding load event handlers on each image, and when they are all fired, re-show the #content div

See this answer for reference: Know when images are uploaded to the AJAX response . He will definitely show you what to do.

+5
source
+1
source

All Articles