Click to See Complete Forum and Search --> : XML image path
mlosier
07-22-2009, 09:47 AM
Hi guys, I am not sure if I can post this here, but i'll do it anyway :P
Ok, i have an xml file like this for example,
<markers>
<image src="images/ad1.jpg"/>
</markers>
I use this code to get the data
$('image', xml).each(function (i) { $("#src").text($(this).attr('src'));
});
How can i show the actual image not just the text?
CoderDan
07-22-2009, 11:42 AM
going to need a little more code than that, as that doesn't appear to be showing anything (although I think it is retrieving the img src, so shouldn't be too hard to wrap an image tag around it on output)
mlosier
07-22-2009, 11:47 AM
how woud I be able to wrap this with a img tag?
CoderDan
07-22-2009, 11:59 AM
where is your output code?
mlosier
07-22-2009, 12:04 PM
This is the output code
<meta http-equiv="Expires" content="Tue, 01 Jan 2000 12:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
</head>
<body>
<div id="src"></div>
</body>
</html>
It's only showing me the image URL which is normal in this case. i want to know how i can parse this to an img tag.
CoderDan
07-22-2009, 12:34 PM
Um, where is it showing the image url? I don't see it.
Weedpacket
07-22-2009, 06:59 PM
Moved to the appropriate forum (yes, a difficult concept, I know....)
mlosier
07-23-2009, 04:58 PM
this here should be working... but it's not, anybody has a clue?
<?php
print "var veh = \"" . $_GET[vehID] . "\";" ;
?>
$.ajax({
type: "GET",
url: "getAds.php",
data: "veh="+veh,
success: function(xml) {
$('img', xml).each(function (i) {
$("#src").html("<img src=\"" + $(this).attr('src') + "\">");
});
setTimeout("refreshData()", 5000);
}
});
}
</script>
<meta http-equiv="Expires" content="Tue, 01 Jan 2000 12:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
</head>
<body>
<div id="src"></div>
</body>
</html>
Thanks in advance
CoderDan
07-23-2009, 05:10 PM
try either:$("#src").innerHTML("<img src=\"" + $(this).attr('src') + "\">"); or change the div to an img and affect it's src instead of innerHTML with just the new src.
(I write a lot of javascript, but I do it from scratch, and I'm nt as good with it as I am with php, so I'm assuming your $('#src") ends up getting the element with that id through some sort of javascript library, and is the equivalent of document.getElementById( 'src' ) )
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.