jquery load image after DOM is loaded

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post December 8th, 2009, 3:56 pm

Okay, need help. Is it possible to load all images within a folder with jquery? I really don't want to use server-side languages on this. How would I get an image to load into the browser after the html has been downloaded?
Use your words like arrows to shoot toward your goal.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 8th, 2009, 3:56 pm

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post December 9th, 2009, 6:31 am

Look into the $.ajax() function of jQuery if you need a callback to your servedr, or you could just build up the image in JavaScript and use append() or one of the various alternatives to it.

I think you would find the API browser helpful.
I'd love to change the world, but they won't give me the source code.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post December 9th, 2009, 9:32 pm

right, I've already got all that. The problem is that when I load the link to the image from an xml datasheet; my <img> tag is being genereated but the image is not being downloaded. I can use firefox's "Web developer" add-on to look at the generated code after the ajax command runs, and the <img> tags are there, with the src attribute pointing to the right images, but no image is rendering.
Use your words like arrows to shoot toward your goal.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post December 9th, 2009, 11:03 pm

okay, I have an idea of how to get this to work...I need to pull the tags from the xml, name them as an array, and then use a seperate ajax call to each image itself that will load the image into the document...now, is it possible to create an array within a function, and then turn it into a global array, rather then local?

I want to create the array within the first ajax call, but this will make it a local array that will be destroyed after that ajax call. If I can make it a global array, I can access the array index with the second ajax call. Can it be done?
Use your words like arrows to shoot toward your goal.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post December 10th, 2009, 8:25 am

Could you share some of the code you're using? It shouldn't be reaching this level of complication for what you're trying to accomplish. We're missing something somewhere. I've used .html("<img src="blah" />) successfully several times (and it loads the image).
I'd love to change the world, but they won't give me the source code.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post December 10th, 2009, 10:03 am

okay, I'm not sure why...or how...but it suddenly works. Finally, good lord that took way too long.
Use your words like arrows to shoot toward your goal.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post December 10th, 2009, 1:05 pm

if you're doing the code placement within your $.ajax success option, then the delay would be from the call/response cycle. Something to keep in mind as you move forward - sometimes those calls can run a little slow, so if the user could be annoyed or think the app is 'broken' during that delay (like waiting 5 secs on an image to come back and load), then you might want to do something like a loading message right before the .ajax function and then remove it within success.
I'd love to change the world, but they won't give me the source code.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post December 10th, 2009, 1:24 pm

I'm going to add an asynchronous function for a loading animation, thanks for the suggestion though!
Use your words like arrows to shoot toward your goal.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 106 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.