Jump to content

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


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.

 

 

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.