why does $.ajax(..) not work for me?
I'm running jquery from a file. And I'm trying to load a svg file from my localhost to populate a svg canvas. However that does not work as expected. What I do from filesystem:
$.ajax({ url: url ,
timeout: 1000,
complete: function(xml) {
alert('complete');
},
开发者_如何学Go success: function(xml, status, xreq) {
alert('success');
},
error: function() {
alert('error');
}
});
the url reads: http://localhost/image.svg, when I read this url directly from an addressbar from the browser, the pages remains white but the pagesource displays the source of image.svg.
Debugging the $.ajax code above, reveals that the success: method is hit, but xml response remains empty. Any help is greatly appreciated. regards, jeroen.If your webserver at localhost does not send the correct mime type for the SVG file then the .ajax call will ignore the contents. Try a vanilla XML file, then rename it to xml.nonsense and you'll see the same effect.
Apparantly Pekka asked the right questions if only I would have payed more attention. The original file (the one loading the svg contents) was served from the filesystem instead of the browser. I'm sure why the ajax read does not work but putting it on the same server solved the problem.
精彩评论