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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Parsing XML data with JS

    Hi folks..

    The web app i'm developing is getting data from an XML file (JQuery) that im generating on the server side, on the fly. I want to get this XML file to parse on my app with JS. Now this is working fine when i point the location of the XML file in the SAME server, "local" to the app.

    But when i try to change the XML file location to a file sitting on an external server, it doesn't seem to recognise its server location. This is prob just a JS issue that i'm not doing correctly, but can someone maybe point out anything please.

    Full XML function is here: http://pastebin.com/6F3uZrBD

    I'm trying:

    Local side (words fine):

    $.ajax({
    type: "GET",
    url: "channel-data.xml",
    dataType: "xml",
    success: function(xml) { ...

    and also external server side (doesnt work):

    $.ajax({
    type: "GET",
    url: "http://www.ExternalServerName.com/channel-data.xml",
    dataType: "xml",
    success: function(xml) { ...


    Many thanks,
    Darren.

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You can't do cross domain ajax requests. What you can do, though, is set up a script on your server that fetches the external xml, and get it from there.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,366
    Thanks
    11
    Thanked 590 Times in 571 Posts
    if you add access-control headers on the remote server's xml output, then you can do cross-site ajax in all browsers newer than IE7.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all, thanks for the replies.
    Rnd, can you give me an example of this?
    Have you tried this already?

    Regards,
    Darren.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,366
    Thanks
    11
    Thanked 590 Times in 571 Posts
    Quote Originally Posted by dmac2010 View Post
    Hi all, thanks for the replies.
    Rnd, can you give me an example of this?
    Have you tried this already?

    Regards,
    Darren.
    i use it all the time.

    here's a good public example of using a small ajax function to grab the contents of a site i built:

    Code:
    function IOx(url, callBack) {
        var x = new XMLHttpRequest;
        if (x.withCredentials != null) { 
        } else if (window.XDomainRequest) {
            x = new XDomainRequest;
        } else {
            return;
        } 
        x.open( "get", url, true);
        x.onload = callBack ? function () {callBack(x.responseText, x);} : String;
        x.send(null);
        return x;
    }
    
    
    
    IOx("http://www.it.illinois.edu/", function(text,ob){
     alert(text);
    });
    (tested in IE8, FF3.6, Ch8)


    if you want XML, obviously the server needs to pass the right mime-type; i couldn't find a working xml example to show, but getting there is the same for .responseText and .responseXML...
    Last edited by rnd me; 01-27-2011 at 12:36 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

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