1

I'm developing a HTML5 application for Blackberry OS 5+.

I'm using jQuery to download and XML file and show it using this function:

$(document).ready(function()
{
    $.ajax({
        type: "GET",
        url: "http://xxx.com/yyy/mTop",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('item').each(function(){
                var tipo = $(this).find('tipo').text();
                var porcentaje = $(this).find('porcentaje').text();
                $('<div class="items"></div>').html('<p>' + tipo + ' - ' + porcentaje + '</p>').appendTo('#page-wrap');
            });
        }
    });
});

But I'm getting this error:

XMLHttpRequest cannot load http://xxx.com/yyy/mTop. Origin file:// is not allowed by Access-Control-Allow-Origin.

How can I parse a remote XML file?

Maybe I need to convert XML retrieved to a DOM object for use with jQuery.

VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • Maybe you can write some server-side code on your server to retrieve the XML file and re-serve it back out to your application. See @Raminson answer below. – carny666 Jul 25 '12 at 17:29

3 Answers3

1

That's because of Same Origin Policy:

The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites

you should use JSONP instead.

Ram
  • 143,282
  • 16
  • 168
  • 197
  • 1
    Yes, but how can I download a XML file a parse it? Your answer doesn't answer my question. – VansFannel Jul 25 '12 at 17:27
  • And, if I to convert XML retrieved to a DOM object, can I parse it this way? I don't know how can I use JSONP to parse an XML document. – VansFannel Jul 25 '12 at 17:34
  • @VansFannel there are many questions regarding this issue on SO, plz check this http://stackoverflow.com/questions/3435454/using-jsonp-when-returning-xml?rq=1 – Ram Jul 25 '12 at 17:37
  • I don't understand anything. I can't change the way server is returning. Server can't be changed. I've checked a lot of questions here and in jquery forum but I don't understand anything. – VansFannel Jul 25 '12 at 17:56
0

Part of your problem is your file path is to a folder and not an XML file. Start there and see if you're problem still exists.

alien.ninja
  • 95
  • 2
  • 13
0

And the reason why you dont have a file location in your link ( url: "http ://xxx.com/yyy/mTop" ) is becouse the site "produces" an xml the moment you visit the folder, slowing down the website each time you reach it..

What you must do is:

go to http ://xxx.com/yyy/mTop on your browser right click - view source code - copy to notepad - save as .xml

upload file to another folder

then change your code url to this url: "http ://xxx.com/yyy/mTop/yourdailyXMLcopy. xml

and keep updating the file daily..else you will kill the server querying each time any user uses your thing for a huge job...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
andreas
  • 16