I want to use an XML file for creating a sort of Dynamic website with jquery.
When testing on a local webserver i see via developer console on chrome that the xml file is not visible.
When opening the homepage in the local file (not using the webserver) I get the following error:
XMLHttpRequest cannot load file /// . Cross origin requests are only supported for protocol schemes: http, data, ...
I read XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP but since am using an IIS local server I already rules that out.
My code for reading the xml:
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: function(xml){
var xmlDoc = $.parseXML(xml);
var root = $(xmlDoc).find("root");
alert(root);
}
});
the project i have exists out of a few files:
index.html
code.js ==> my own code
jquery.js ==> jquery code
style.css
data.xml
Web.config ==> I'm not entirely sure if i need this since i won't be using connections.
Website.sln ==> I use a vs2013 express edition
This is my first project with jquery and though the adding and dropping of html content works perfectly, reading out an XML file keeps me at bay. I created a web.config file via visual studio express but i'm not entirely sure that i need this.
EDIT:
with the following changes I got it done:
firstly: replace the data.xml to a subdirectory (I don't know if it was this or not)
secondly: drop the parseXML function and go for a
$(this).find(name).each(function(){ //your code });
Eh voila, no back to programming...