Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Steam API using XML and Javascript

    I recently came into a problem while using the Steam API, the same problem a person here ran into. Although thinking that I fixed it by downloading the code separately using a function called "LoadXML", it still did not work.

    After spending two days puzzling it over, I decided to put it to the community, is it terrible coding on my part, or some hidden problem with XML parsing? The JavaScript is below and the HTML used by said JavaScript is an input box called "SteamID", a text field called "Test" and a button with a function of "getName()".

    <script>
    function loadXML(source) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
    } else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", source, false);
    xmlhttp.send();
    return xmlhttp.responseXML;
    }

    function getName() {
    var SteamID = document.getElementById("SteamID").value;
    console.log(SteamID);
    //Test if this function gets called - Copies text box message into name
    //document.getElementById("Test").innerHTML = SteamID;

    if (SteamID !== "") {
    var requestLink = "http://steamcommunity.com/id/" + SteamID + "/?xml=1";
    var xmlReturn = loadXML(requestLink);
    var accountID = xmlReturn.getTagById('steamID64').childNodes[0].nodeValue;
    document.getElementById("Test").innerHTML = accountID;
    }
    }
    </script>

    The full code is available here at Docs.Google after request. It's read-only, and I didn't know a better code sharing website, so please also say a better one.

    Also, yet another quick note here, the rest of our code uses JSON and javascript appears to be able to use it with greater ease - if anyone finds a way to do this with JSON I would greatly appreciate it. The way we do it is going to http://steamcommunity.com/id/xxXNameXxx/?xml=1 where the name is the SteamID. It returns an XML page which says:

    <steamID64>76561198039191886</steamID64>

    And that is what we are trying to find and extract.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,297
    Thanks
    10
    Thanked 282 Times in 281 Posts
    I don't know all the details, but what makes you think you aren't a victim of the same cross origin policy problem as the one you linked?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •