#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Trouble with accessing online XML


    Hi everyone, I am trying to access an online XML file, for example: http://www.rgraph.net/sample.xml using HTML.

    Code:
    <html>
    <body>
    
    <script type="text/javascript">
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    var url = "http://www.rgraph.net/sample.xml";
    xmlhttp.open("GET",url,false); //If url is replaced by the downloaded file named "sample.xml" this works and give the output of 1.
    // but works only on Mozilla
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    
    var x=xmlDoc.getElementsByTagName("stats");
    alert(x.length);
    
    </script>
    
    </body>
    </html>
    Any comment or advice would be much appreciated!

    PS: Why does this only work on Mozilla and NOT on Safari or Chrome?

    Many thanks!
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    Is your website www.rgraph.net? For security reasons you normally cannot issue an XHR request to a different domain than the page issuing it, I suspect that's the issue here.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0
    @E-Oreo

    That is indeed it! After sm research i came to the same conclusion. is there any way data on the XML of another website can be read or accessed? also do you hav any idea why this piece of code doesnot work on safari or chrome?

    Many thanks!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    10
    Rep Power
    0

    Reply


    Indeed,can we verify our doubts in online? if any websites,kindly post in this forum.

IMN logo majestic logo threadwatch logo seochat tools logo