aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Dynamic Image Loading without Page Refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Dynamic Image Loading without Page Refresh" Watch "Dynamic Image Loading without Page Refresh" New topic
Author

Dynamic Image Loading without Page Refresh

Divya Guttikonda
Ranch Hand

Joined: Mar 09, 2005
Posts: 47
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Why do you need Ajax?

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

Eric
Divya Guttikonda
Ranch Hand

Joined: Mar 09, 2005
Posts: 47
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Mar 09, 2005
Posts: 47
yup..i got it.Thanks Eric.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Image Loading without Page Refresh