views:

351

answers:

1

I'm new to this site, but it seems like someone out there should be able to answer my question.

I've recently started using jQuery, and spent the day slamming my head against the desk trying to successfully parse an XML file and append the text to a div. After failing at this in Safari, I switched over to Firefox, and found it working perfectly! Furthermore, when I loaded the files to my server and loaded the same page in Safari, it works fine there too! It seems that Safari is having trouble parsing from a local XML file. Has anyone experienced this, and have any explanation or solution? Here's my code:

$(document).ready(function(){
  $.get('datafile.xml',{},function(data){
    $(data).find('item').each(function(){
      var dataHolder = ($(this).find('title').text());
      $('#textBox').append(dataHolder + "<br />");
    }); 
  }); 
});

Again, this works perfectly both locally and remotely in Firefox and also works in Safari remotely. Locally, Safari doesn't work.

If anyone wants to see the HTML file as well, let me know. It's pretty straightforward. Just a div with an id of textBox. The XML file is as well. Just a list of items and titles.

Thanks a million in advance to anyone who can help me out with this!

A: 

What response are you getting from the server when you make your GET request? If you use $.ajax and specify an error handler, is the error handler getting called? It seems like you might be hitting XSS protection somehow, but I don't see how local > local would fail.

If this is the issue, then there is no workaround aside from running Apache/web container locally and serving the xml file and html file with javascript both from the web container.

Stefan Kendall
Stefan,Interestingly enough, switching to $.ajax seems to have cleared the problem up. I did it originally assuming it would throw an error, but for whatever reason, $.ajax seems to work where $.get doesn't. Any idea why? Anyway, thanks for the help!
Travmatron86
...no problem, I guess. :P I have no idea wehre one would work over the other. I only assumed that the error message would have turned up something useful.
Stefan Kendall