0

Hi All:

I am trying to load an image into a div using AJAX.
Instead on loading the image, I get �PNG as the result in the div.

Does anyone know how to load an image into a div?

Best Regards,
dennishall

2
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by hielo
1

What you are actually (incorrectly) doing now is inserting the "BINARY" image content into the div. What you need to do is to insert and <IMG> tag into the div and set the SRC attribute to the path of the image. The browser will take care of the rendering.

Votes + Comments
nice, getting all that from such a short post
0

What you are actually (incorrectly) doing now is inserting the "BINARY" image content into the div. What you need to do is to insert and <IMG> tag into the div and set the SRC attribute to the path of the image. The browser will take care of the rendering.

Thanks for the reply hielo:

My bad, I failed to mention that I'm loading the image via javascript.
The onclick syntax is the javascript('file', 'div_id')

I'm at a loss as to where I can insert the image tag in the following line of code:
<a href="javascript:void(0)" onclick="ajaxpage('image.png', 'rightcolumn');">Image 1</a>

Best Regards,
dennishall

0
function ajaxpage(url,container)
{
 if(/\.(gif|png|jpg)$/i.test(url))
 {
   document.getElementById(container).innerHTML='<img src="'+url+'" alt="" />';
  return;
 }
 //whatever you currently have, should remain untouched
 ...
}
0
function ajaxpage(url,container)
{
 if(/\.(gif|png|jpg)$/i.test(url))
 {
   document.getElementById(container).innerHTML='<img src="'+url+'" alt="" />';
  return;
 }
 //whatever you currently have, should remain untouched
 ...
}

Thanks hielo:

I inserted the javascript you supplied into line 3 of the ajaxpage script, verified if I needed to change anything else to avoid conflict. I did not need to change anything else.

It worked out of the box.
This issue is resolved.

UR the best,
dennishall

0

Glad to help Little Grasshopper.

Regards,
Hielo

Edited by hielo: typo

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.