【问题标题】:Phonegap build XML requestPhonegap 构建 XML 请求
【发布时间】:2013-11-27 15:47:23
【问题描述】:

我使用下面的代码从 XML 文件中获取信息。 它确实可以在我的笔记本电脑上使用,并直接使用文件浏览器加载 html 文件。 但是,它不适用于由 phonegap 构建创建的应用程序。 我正在使用 android 4.3。希望有人知道答案。

var Connect = new XMLHttpRequest()
Connect.open("GET", "data/test.xml", false);
Connect.setRequestHeader("Content-Type", "text/xml");
Connect.send(null);
var TheDocument = Connect.responseXML;
var workid = TheDocument.childNodes[0];
for (var i = 0; i < workid.children.length; i++)
{
var id = workid.children[i];
var Name = id.getElementsByTagName("title");
document.write(Name[0].textContent.toString());
  }

希望你能帮忙!

【问题讨论】:

  • 您在调试窗口中收到任何消息?

标签: javascript android html xml cordova


【解决方案1】:

对于其他有同样问题的人:使用以下代码让它工作。

<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
} 
</script>

</head>

<body>

<div class="frame">

<script>
xmlDoc=loadXMLDoc("test.xml");
x=xmlDoc.getElementsByTagName("title");
document.write(x[0].childNodes[0].nodeValue);
alert('loaded');
</script>

</div>

</body>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多