Jump to content

How can we display image using ajax


sajan
 Share

Recommended Posts

Hi I use prototype frame work.When i try to display image using ajax response,i get the characters instead of image.What should i do to display image.my code

<table align="center" width="400"><tr><td><a href="#" onclick="drawFigure('1')">Draw Circle</a></td><td><div><img id="circle"/></div></td></tr></table>

ajax code

function handleResponse(response) 			{ 		  $('circle').innerHTML=response;							 }

Link to comment
Share on other sites

:) you don't need to call an image using AJAX, you can just write an <img /> tag to the document or change the src of an image tag and the image will be displayed. AJAX is for text and XML data. So your drawFigure() function may look like this
function drawFigure(figure) {document.getElementById('circle').src = "images/figure_" + figure + ".gif";}

That is all :) no need for AJAX.

Link to comment
Share on other sites

Doesn't matter, just reference the PHP script in the src attribute of the image. You can pass parameters through the querystring, e.g.

<img src="draw_figur.php?fig=1" />

function drawFigure(figure) {document.getElementById('circle').src = "draw_figur.php?fig=" + figure;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...