【问题标题】:Windows 8 javascript html5 app not parsing xmlWindows 8 javascript html5 应用程序不解析 xml
【发布时间】:2013-04-08 20:02:05
【问题描述】:

当我使用本地 HTML 和 XML 文件在 Firefox 中加载它时,我的 javascript XML 解析代码工作正常,但是当我使用相同的代码在 Visual Studio 2012(HTML5 javascript 应用程序)中构建我的应用程序时,它无法解析 XML 文件。

<script type="text/javascript">
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "pages/home/example.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;

//Content
txt = xmlDoc.getElementsByTagName("Symbol")[0].childNodes[0].nodeValue;
document.write(txt + "  ");

【问题讨论】:

  • 你为什么不用winjs库?

标签: javascript xml html windows-8 xml-parsing


【解决方案1】:

加载后才能获取responseXML。

var xmlDoc
xmlhttp.open("GET", "pages/home/example.xml", false);
xmlhttp.onload = function(){
  xmlDoc = xmlhttp.responseXML
}
xmlhttp.send();

【讨论】:

  • 这会导致同样的问题。应用程序构建,然后返回到 Windows 8 开始屏幕。没有显示错误。
  • 如果这个问题仍然存在,您必须在调用 onload 函数之前发送请求;) var oReq = new XMLHttpRequest(); oReq.open("GET", 'pages/home/example.xml', false); oReq.send(); oReq.onload = function(){ var xmlDoc = oReq.responseXML; } console.log(oReq.responseXML.xml);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 2015-10-18
  • 1970-01-01
相关资源
最近更新 更多