I'm writing a small program in JavaScript to read data from a local XML file. When I try to load this file, I get an error from IE9 saying:
SCRIPT5: Access is denied
When I try to load the same in Chrome, I get an error saying:
XMLHttpRequest cannot load file://... cross origin requests are only supported for HTTP
and
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file...
The following is my code:
<!DOCTYPE html>
<html>
<head>
<h1 id="si">Search Input</h1>
<button onclick="promptSearch()">Search By Vessel Name</button>
<h1 id="sr">Search Result</h1>
<script>
function loadXMLDoc(filename) {
if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest();
}
else { // for IE5 and IE6
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
}
function promptSearch() {
var prmpt = window.prompt("PLease enter vessel name:", "Vessel Name");
var search= prmpt.toLowerCase();
if(prmpt != null){
document.getElementById("si").innerHTML = search;
}
document.getElementById("sr").innerHTML = searchData();
}
function searchData() {
xmlDoc=loadXMLDoc("vesselData.xml");
}
</script>
</head>
</html>