NachtmannM
NachtmannM

Reputation: 47

XML request in jQuery gets ignored

I have build a webpage that focuses a lot on an XML file to populate it. Now I generated a second one for some additional tasks. Unfortunatly, everytime I try to parse it, it dows not succeed.

I am using very simple code to demonstrate the problem. I stripped the function, so everything it does is writing strings into the browser console.

Once I excecute this code, all I get is "pos1, pos3, pos4" So the success function is not even excecuted. I know this sounds like a dumb question, but it is really hard for me, to find my mistake right now.

function insertFirstBeginnerQuestion(){

console.log('pos1');

$.ajax({
    url: 'xml/questions.xml',
    type: 'get',
    dataType: 'xml',
    success: function(data) {console.log('pos2');},
    error: function(){console.log('pos3');},

});

console.log('pos4');

};

Upvotes: 0

Views: 27

Answers (1)

JPS
JPS

Reputation: 2760

Are you trying it in server? Your code works for me and loads the xml properly. GET is a HTTP method, so you have to deploy this in a server and access using http protocol. Otherwise this will give you 404 error while trying to load the xml file.

Upvotes: 1

Related Questions