382 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
blabus says

Alright, I will be truly indebted to anyone who can help me figure this one out. :)

So I’m building a web app that provides music information (i.e. info on artists, albums, songs, etc.) and for the info source I’m using the MusicBrainz API .

Now, I’m trying to load the data from an API call and process it, with jQuery. This is the code I’m using:

queryString="http://musicbrainz.org/ws/1/artist/?type=xml&name="+qry+"&limit=10"; 
$.ajax({url: queryString, dataType: ($.browser.msie) ? "text" : "xml", success: function(data){ 
      alert("success"); 
      var xml; 
      if (typeof data == "string") { 
             xml = new ActiveXObject("Microsoft.XMLDOM"); 
             xml.async = false; 
             xml.loadXML(data); 
        } else { 
             xml = data; 
        }; 
...

With ‘queryString’ being the URL string for the request, and then I’d proceed to read the data out of the ‘xml’ object. Fairly simple.

However, this is where problems arise. The code works flawlessly when running locally on my computer, but does not work at all when I upload everything to my web server and try to run it there. I did some reading and have discovered that AJAX calls can’t be made across different domains, due to security issues.

So I’ve read through numerous solutions, but almost all require either something with PHP (which I have absolutely NO knowledge of) or grabbing the data in JSON format (which apparently isn’t subject to the same security restrictions). However, my main problem is that the MusicBrainz API does not return data in JSON format (in fact the only format it returns is XML ).

So in any event, I was basically just wondering if anyone could give me some help or pointers on if and how I could grab that remote XML file using only JS/jQuery. Or, point me toward another method that could be accomplished by a complete PHP noob like myself. :)

Thanks for any help!

9 posts
  • Has been part of the Envato Community for over 5 years
  • Located in Australia
  • Sells items exclusively on Envato Market
nafis says

There is a really cool site for programming questions like these – http://stackoverflow.com/

3 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
pixoload says

Come on Bill, you’re gonna have to learn PHP to use cross-site scripting or whatever it’s called, but I am sure that http://simplepie.org/ will help you ;)

All this means is I need to buy an iPod Touch, don’t I?

EDIT : http://www.bobulous.org.uk/coding/php-xml-feeds.html seems a lot better.

382 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
blabus says

Yeah yeah, I’ve been trying to avoid learning PHP at all costs. :D

@nafis: Thanks for that link, I’ll post the question there as well.

Also, I came up with one other possible solution (no idea if it would work or not): Would it be possible to use PHP to download a copy of the XML file (returned by the API ) to my own site’s directory? Because if so, that would allow me to access the data through JavaScript, as I’d be reading the local copy off my own server.

1 post
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in Sweden
Tanax says

www.talkphp.com

Try asking there for help.

by
by
by
by
by
by