Jump to content

How to pass images not just text?


11Tami

Recommended Posts

Hello I have a function that returns text only. How would I adjust this if I wanted it to get images too?

 

function handleResponse() {

   

        if(http.readyState == 4 && http.status == 200){

   

            // Text returned FROM PHP script

            var response = http.responseText;

   

            if(response) {

                // UPDATE ajaxTest content

                document.getElementById("countPosts").innerHTML = response;

                setTimeout('countPosts()',2000);

            }

 

I would imagine I would also add this

document.getElementById("countPosts").src = response;

But then I'm not sure what I would do with this--how would I add an image src to this next?

var response = http.responseText;

Please let me know, thank you very much.

 

Link to comment
Share on other sites

I think I'm taking the wrong approach on this. The http request is calling another page called test.php. And putting it all in an id called "countposts." I'm trying to pull an image from that page. So basically I'm just trying to call whats in the page, not any text at all. So I think I can get rid of the text commands in the javascript and do something like this instead. But I think there is something missing in the getelement by id, like a src. command or something. Anyone know how to take an image from a php page and stick it in an id?

function handleResponse() {

   

        if(http.readyState == 4 && http.status == 200){

    document.getElementById("countPosts")

                setTimeout('countPosts()',2000);

            }

 

Link to comment
Share on other sites

Thats a unique approach. Downside is this is how it loads, with no image appearing because of it.

http://www.website.com/%3Cimg%20src='/file02.jpg'%3E

 

So I put this in the brackets and the double quotations instead.

<img src="=<?php echo $imageurl; ?>"> 

 

Great thing is the images appeared! But now I have this on the viewing part of the page on both sides of the image.

<img src="">   

Anyone know how I can get rid of it? Once that is gone I'll be good to go.

Thank you very much.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.