Advertisement Jump to content
Sign in to follow this  

Changing an image with AJAX

This topic is 4902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On a website I have an image and some buttons. The image is generated by a server-side script which I call through an XMLHttpRequest both when the page is loaded ("onload") and when the buttons are pressed. The script regenerates the image and returns it's name and path (which remain the same for multiple calls). When I first create the page I just write an "img src="picture.jpg"" tag and the image is loaded when the script executes for the first time.
function handleHttpResponse()
   if (http.readyState == 4)
      document.images[2].src = http.responseText;
I use that code to change the image but the HTML code of the page doesn't change. How can I get my image to be changed and refreshed when I press the buttons? Another thing: how can I use "hover" CSS for "td" table cells? (i want the whole cell to change color on hover, a cell contains an image)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!