Jump to content

Receive XML information and using the information[AJAX PHP JS]


orcmar

Recommended Posts

This is my first time coding Ajax, When i try to use this code which i basicly made my self nothing happens. So i was wondering if someone could help me to fix this.

 

JS & AJAX code:

<script type="text/javascript">
function loadsteamimage(imgid, steamid) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
	if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
		document.getElementById(imgid).src = xmlhttp.getElementsByTagName("avatarMedium");
	}
}
xmlhttp.open("GET","http://steamcommunity.com/profiles/" + steamid + "/?xml=1",true);
xmlhttp.send();
}
</script>

 

PHP code:

$steamid = "STEAM_0:1:55";
$parts = explode( ":", str_ireplace( "STEAM_0:", "", $steamid ) );
$friendid = bcadd( bcmul( $parts[ 1 ], "2" ), bcadd( "76561197960265728", $parts[ 0 ] ) );
$imgid = "testimg";
echo "<img src='images/noimage.png' id='testimg' onFinish='loadsteamimage($imgid,$friendid);'/>";

 

It would help me alot if someone could fix this code!

 

Thank's for taking your time to read & trying to help!

This is just a guess, but this line:

document.getElementById(imgid).src = xmlhttp.getElementsByTagName("avatarMedium");

 

Should look something more along these lines:

document.getElementById(imgid).src = xmlhttp.responseText;

 

I'm taking it that the return here is the image src.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.