1

I´m trying to load the content of an xml file into an html element using the JQuery $.get(url, data, callback) method. Here is explicitly the code that I wrote:

function loadFileToElement(filename, elementId) {
    var path = filename + ".xml";
    var component = document.getElementById(elementId);

    try {
        $.get(path, 
              function(data) {
                    component.innerHTML = data;
        });

    } catch (e) {
        window.alert("Unable to load the requested file " + filename);
    }
}

This code works smoothly in IE, but not in Firefox and Google Chrome. By debugging the loadFileToElement() method I figured out that the callback method was not executed. Any Help ? Thanks in advance

grexter89
  • 1,048
  • 9
  • 22
user2315181
  • 29
  • 1
  • 4
  • 3
    If the callback isn't getting executed, then there must've been an error retrieving the file. Is this a local file? Are you running this on a web server, or are you running it off the local file system. I suspect Chrome is blocking you from accessing the local file system file via AJAX. – crush Sep 12 '13 at 11:38
  • Yes, this is a local file and I´m running the this on my local file system – user2315181 Sep 12 '13 at 11:41
  • Please [see this Q&A](http://stackoverflow.com/questions/3102819/chrome-disable-same-origin-policy). This is the issue you are facing. – crush Sep 12 '13 at 12:34

0 Answers0