Question

Just trying to load a simple XML file in my Marmalade web app (based on PhoneGap) with the following jQuery code:

$.ajax({
    type: "GET",
    url: "books.xml",
    dataType: "xml",
    success: function(xml) {
        alert("SUCCESS");
    },
    error: function(result) {     
            alert("FAILED : " + result.status + ' ' + result.statusText);  
    }
});

I'm getting a 404 error, however. The file is in the same directory as the HTML file the JavaScript above is contained in. I've also tried adding "file:///" to the beginning of the URL, but to no avail.

After searching for a couple of hours, I've found no solutions for the problem. Any ideas?

Your help is appreciated! -SL

Was it helpful?

Solution

First thing I would do is take jQuery out of the equation and just try a plain vanilla AJAX call:

var request = new XMLHttpRequest();
request.open("GET", "books.xml", true);
request.onreadystatechange = function() {
    if (request.readyState == 4) {
        if (request.status == 200 || request.status == 0) {
            alert("SUCCESS");
            var books = request.responseXML;
        }
    }
}
request.send();

If books.xml is in the same directory as your HTML file that should just work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top