admin管理员组文章数量:1366123
Nothing gets printed on the web page when I try to open an HTML file having javascript. The script inside the html code loads the xml file and tries to print some element data. I have pasted the code below. Sadly no data of file gets printed. I have used browsers IE8 and Chrome. Please let me know what is the issue.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLDOM");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script>
xmlDoc=loadXMLDoc("file:///E:/Parser/book.xml");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + " <br>");
document.write(xmlDoc.getElementsByTagName("authors")[0].childNodes[0].nodeValue + "<br>");
</script>
</body>
</html>
Nothing gets printed on the web page when I try to open an HTML file having javascript. The script inside the html code loads the xml file and tries to print some element data. I have pasted the code below. Sadly no data of file gets printed. I have used browsers IE8 and Chrome. Please let me know what is the issue.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLDOM");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script>
xmlDoc=loadXMLDoc("file:///E:/Parser/book.xml");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + " <br>");
document.write(xmlDoc.getElementsByTagName("authors")[0].childNodes[0].nodeValue + "<br>");
</script>
</body>
</html>
Share
edited Aug 17, 2013 at 19:33
Jaak Kütt
2,6564 gold badges33 silver badges40 bronze badges
asked Aug 17, 2013 at 19:24
user2281107user2281107
3192 gold badges5 silver badges14 bronze badges
2
- 1 You're definitely not going to get any joy with Chrome since you're using ActiveX. Any chance you can build a web service to surface that XML file? – Mister Epic Commented Aug 17, 2013 at 20:24
- any errors in your console? – metadings Commented Aug 17, 2013 at 20:25
1 Answer
Reset to default 4You can't open a local file using ajax
xmlDoc=loadXMLDoc("file:///E:/Parser/book.xml");
this can't be performed because JavaScript running in a web browser does not have access to the local filesystem. That would a huge security risk.
本文标签: htmlLoad xml file using javascriptStack Overflow
版权声明:本文标题:html - Load xml file using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743773431a2536538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论