2012-07-16 65 views
0

Phonegap.Iam在phonegap中做一個應用程序,在這裏我想從一個特定的url中獲取數據。這些數據是在xml文件中。任何人都可以通過建議幫助我一些想法。從phonegap中獲取url的數據

在此先感謝...

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> 

回答

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(); 
+0

感謝您reply.But它仍然不是working.I已經改變了代碼,並使用完整的代碼中給出主要問題領域。請你找出問題所在。 – Balu 2012-07-17 07:21:13