changing image source

D

david.sargent

ok, I am just learning this stuff, small stupid question here...I am
trying to swap images in a little ajax application, and the code
handling that looks like...


document.placeholder.src =xmlHttp.responseText


/
no big deal i know, if i print xmlHttp.responseText to the screen the
link is correct, but anytime I assign it as a src, i get the link+(all
the page html attached on the end) and i dont know why?

this is driving me crazy
 
R

Randy Webb

(e-mail address removed) said the following on 5/2/2006 11:17 AM:
ok, I am just learning this stuff, small stupid question here...I am
trying to swap images in a little ajax application, and the code
handling that looks like...

document.placeholder.src =xmlHttp.responseText

I hope placeholder is an image tag....

document.images['placeholder'].src is less ambiguous.
no big deal i know, if i print xmlHttp.responseText to the screen the
link is correct,

What "link" is correct? Are you trying to create a link or change an image?
but anytime I assign it as a src, i get the link+(all
the page html attached on the end) and i dont know why?

Problably something in the responseText doesn't close a tag. Or,
something else is screwing it up.

Post a sample page URL that has your code in it.
 
D

david.sargent

ok, since this is a little ajax thing, i have it handling the response
like this

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.images['placeholder'].src =xmlHttp.responseText
}
}

now, if i change it to write a message based on the xml response, it
displays like it should, only with the image it screws up...

if i just do document.write(xmlHttp.responseText) it prints out:

http://static.flickr.com/48/131196335_d17ea359ff_s.jpg ----> THIS IS
CORRECT


http://static.flickr.com/48/1311963... <div> </div> </form></body></html>

---->this is not...


what is happening?
 
L

Lee

(e-mail address removed) said:
ok, since this is a little ajax thing, i have it handling the response
like this

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.images['placeholder'].src =xmlHttp.responseText
}
}

now, if i change it to write a message based on the xml response, it
displays like it should, only with the image it screws up...

if i just do document.write(xmlHttp.responseText) it prints out:

http://static.flickr.com/48/131196335_d17ea359ff_s.jpg ----> THIS IS
CORRECT

Off the top of my head, try:
document.images['placeholder'].src=xmlHttp.responseText.toString();


--
 
D

david sargent

that didnt seem to do it...i am really confused by this, it will print
out the string fine, but as soon as I try to assing the URL to a photo
as its source, it gets jumbled...
 
E

Evertjan.

david sargent wrote on 02 mei 2006 in comp.lang.javascript:
that didnt seem to do it...i am really confused by this, it will print
out the string fine, but as soon as I try to assing the URL to a photo
as its source, it gets jumbled...

Please quote what you are replying to. This is not email, but usenet.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>
 
D

david sargent

i am sorry, new to google groups...


Evertjan. said:
david sargent wrote on 02 mei 2006 in comp.lang.javascript:


Please quote what you are replying to. This is not email, but usenet.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>
 
R

Randy Webb

david sargent said the following on 5/2/2006 5:37 PM:
that didnt seem to do it...i am really confused by this, it will print
out the string fine, but as soon as I try to assing the URL to a photo
as its source, it gets jumbled...

I will refrain from repeating what Evertjan said about quoting, but
please don't top post either.

Try setting a variable to the responseText, alert that responseText, and
then set the src to the variable:

myVar = xmlHttp.responseText;
alert(myVar);
alert('typeof myVar is ' + typeof(myVar));
alert('typeof xmlHttp.responseText is ' + typeof(xmlHttp.responseText));

What do the two typeof's give you?
 
D

david sargent

Try setting a variable to the responseText, alert that responseText, and
then set the src to the variable:

myVar = xmlHttp.responseText;
alert(myVar);
alert('typeof myVar is ' + typeof(myVar));
alert('typeof xmlHttp.responseText is ' + typeof(xmlHttp.responseText));

What do the two typeof's give you?


Both say typeof string, but when the alert(myVar) pops up, it shows the
additional text on the end...when I just do a
document.write(xmlHttp.responseText) it gives me just the url...
 
E

Evertjan.

david sargent wrote on 02 mei 2006 in comp.lang.javascript:
i am sorry, new to google groups...

That be as it is,
but comp.lang.javascript is NOT a Google group,
it is a Usenet goup.

Google is only the portal you use.

Better use a dedicated news-reader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top