2013-11-14 77 views
2

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

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()); 
    } 

希望你能帮助!

+0

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

回答

0

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

<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>