我很熟悉Phonegap.Iam在phonegap中做一个应用程序,在这里我想从特定网址获取数据。数据在xml文件中。任何人都可以通过提出一些想法来帮助我。
提前致谢...
html>
<head>
<title>Xml file read</title>
<script type="text/javascript">
function loadXMLDoc()
{
var request = new XMLHttpRequest();
request.open("GET","http://saletrack.cynere.net/test2.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 0) {
return request.responseXML;
// do something with my xml
}
}
}
request.send();
}
</script>
</head>
<body>
<script type="text/javascript">
var xmlDoc=loadXMLDoc();
var x=xmlDoc.getElementsByTagName("author");
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("<br />");
}
</script>
</body>
</html>
答案 0 :(得分:1)
使用AJAX:
var request = new XMLHttpRequest();
request.open("GET", "http://saletrack.cynere.net/App.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 0) {
var myXML = request.responseXML;
// do something with my xml
}
}
}
request.send();