我是 html 和 javascript 新手,需要一些帮助。
所以我有一个html
其上有一个按钮的页面。当我单击该按钮时,我希望它加载 xml document
(并最终显示其中的某种信息)。我不知道我没有正确加载文件。如果我注释掉 xhttp.send;
它会贯穿。所以行 xttp.send
是我遇到问题的地方。
要考虑的注意事项:我正在写 notepad++
,.xml
文件与我的 .html
位于同一目录中文件,我正在使用chrome
作为浏览器。
提前致谢
var xhttp;
function functionName(){
xhttp=new XMLHttpRequest();
xhttp.open("GET","test.xml", false);
xhttp.send();
//xmlDoc=xmlhttp.responseXML;
//var temp = xmlDoc.getElementsByTagName("alerts");
alert("something");
}
</script>
最佳答案
您必须提供 xml 资源的完整 http 路径。
关于javascript - 为什么我的 html 请求在 javascript 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21977829/