orcmar Posted July 26, 2012 Share Posted July 26, 2012 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! Link to comment https://forums.phpfreaks.com/topic/266282-receive-xml-information-and-using-the-informationajax-php-js/ Share on other sites More sharing options...
sunfighter Posted July 28, 2012 Share Posted July 28, 2012 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. Link to comment https://forums.phpfreaks.com/topic/266282-receive-xml-information-and-using-the-informationajax-php-js/#findComment-1365062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.