2013-09-30 124 views
0

蔭新的PhoneGap,蔭無法獲得響應,同時解析XML Url.what我曾嘗試是,XML解析錯誤的PhoneGap

function initLoginPage() {  
    var xmlhttp = new XMLHttpRequest(); 
    var urlString = "url/app/api.php?fn=employees"; 
    xmlhttp.onreadystatechange = processData; 
    xmlhttp.open("GET", urlString, true); 
    xmlhttp.send(); 
} 

function processData() {  
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ 
      document.getElementById("result").innerHTML=xmlhttp.responseText;      
       } else{document.getElementById().innerHTML = "<b>Please Wait..</b>";} 
} 

我呼籲initLoginPage功能,當設備Ready.I必須在listView中顯示Response。 IAM使用URL的JQuery的Mobile.The響應是

<?xml version="1.0" encoding="UTF-8" ?> 
<details> 
<responsecode>200</responsecode> 
<Employee> 
<name>name</name> 
<Fathername>fathename</Fathername> 
<Address>address</Address> 
<Number>12342456</Number> 
<Enumber>4324421341234</Enumber> 
<OfficeMail>[email protected]</OfficeMail> 
<PersonalMail>[email protected]</PersonalMail> 
<EmployeeID>1</EmployeeID> 
<DOB>21-06-1991</DOB> 
<DOJ>05-03-2013</DOJ> 
<PanNumber>123456</PanNumber> 
<image>./images/1380372683.png</image> 
</Employee> 
</details> 

回答

0

喲具有不弄錯

var urlString = url+"/app/api.php?fn=employees"; 
+2

實際上它完整的URL,我沒有提到的域名地址 – geeko

0

可變XMLHTTP僅在initLoginPage功能的範圍來限定,因此它沒有在過程數據中定義。

有兩種方法可以解決您的問題。您在過程數據使用,而不是XMLHTTP:

function initLoginPage() {  
    var xmlhttp = new XMLHttpRequest(); 
    var urlString = "url/app/api.php?fn=employees"; 
    xmlhttp.onreadystatechange = processData; 
    xmlhttp.open("GET", urlString, true); 
    xmlhttp.send(); 
} 

function processData() {  
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("result").innerHTML = this.responseText;      
    } 
    else { 
     document.getElementById().innerHTML = "<b>Please Wait..</b>";} 
    } 
} 

或者直接傳遞過程數據作爲一個匿名函數xmlhttp.onreadystatechange:

function initLoginPage() {  
    var xmlhttp = new XMLHttpRequest(); 
    var urlString = "url/app/api.php?fn=employees"; 
    xmlhttp.onreadystatechange = function() {  
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      document.getElementById("result").innerHTML = xmlhttp.responseText;      
     } 
     else { 
      document.getElementById().innerHTML = "<b>Please Wait..</b>";} 
     } 
    } 
    xmlhttp.open("GET", urlString, true); 
    xmlhttp.send(); 
}