I'm having an issue and I'm hoping someone could point me in the right direction. I'm trying to parse an xml file using JQuery's .ajax function this is the code:
This code resides in a test.js file
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'test.xml',
dataType: 'xml',
success: testIt
});
});
function testIt(xml) {
alert("Test");
}
This is just a test I'm running at the moment that after performing the ajax request it should call testIt
. The problem is it doesn't. As this is a test the html, js and xml files are all in the same directory on my Desktop ie /Users/Chris/Desktop/Development
.
If I add complete: testIt
it does go into the function. the test.xml and has been checked and is valid.
I'm currently testing using Safari 5.0.5 but I have also tested it in Firefox which acts the same. It is either a quirk of $.ajax
or more likely its something I'm doing wrong.
Any help would be appreciated
Have a go at Firebug, or the built-in developer tools in Chrome, and take a closer look at the request and results from your ajax call. If success
doesn't run, but complete
does, it is likely that the call comes back with an error status for some reason (likely because of the details subtenante outlined in his answer).
I tried your setup on my machine, and added error: function() { alert("didn't work..."); }
to the ajax options, and as I suspected the request comes back with an error code.
If you're going to use this online in the end, I suggest you upload the xml file somewhere and try to load it from there, to see if that works. (If you're running a local webserver, "somewhere" might be your own computer, but you must link to it with a "real" url, like localhost:8080/something/test.xml).