• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Image Loading without Page Refresh

 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I had this problem where i had to load an image into an already existing page without refreshing the whole page.The problem is that this image url is dynamically constructed based on the values given by the user in that page.Can anyone suggest me some nice idea about using this using javascript.My application has no servlets,just simple java classes.Can i use AJAX?If so how can i redirect that to a java method to construct the url from within AJAX?

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need Ajax?

document.getElementById("imgId").src = jsVariable;

Eric
 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.The situation is like the user has to click a button to preview the image after giving some details.Upon clicking the button i am sending it to a java class where i have to construct the url and return it back to the same jsp page.And then as you are suggesting i can write this code [ document.getElementById("imgid").src = "url" ]...Can this happen without page refresh?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still do not need Ajax to do this:

instead of setting the image src to the exact image, set it to the serverside page that determines the image along with the data you need to pass along

document.getElementById("imgId").src = "yourServerSidePage.jsp?foo=" + bar;

and look at doing something like this on the server:

http://www.rgagnon.com/javadetails/java-0366.html

I do somethign similiar in my C# application for adding tracking images to emails.

Eric
 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup..i got it.Thanks Eric.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic