Jump to content

How can we display image using ajax


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...