Jump to content

Phonegap and restful web service


Recommended Posts

I want to retrieve data from restful webservice that returns xml. I'm using phonegap for Android.

I have tried this code, it gives me result on InternetExplorer but not on my phone gap app!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>PhoneGap</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
  <script type="text/javascript" charset="utf-8" src="js/Config/phonegap-0.9.3.js"></script>[/size]

[size=4]   <link rel="stylesheet" href="css/jquery/jquery.mobile-1.0a1.min.css" />
  <link rel="stylesheet" href="css/Style.css" />
  <script src="js/Config/jquery-1.4.3.min.js"></script>
  <script src="js/Config/jquery.mobile-1.0a1.min.js"></script>[/size]
[size=4]<script type="text/javascript">[/size]
[size=4]function getDescription() {
var url = 'http://localhost/prestashop/api/customers/2';
req = new XMLHttpRequest();[/size]
[size=4]req.onreadystatechange = processRequest;
req.open("GET", url, true);
req.send(null);
}
function processRequest() {
if (req.readyState == 4) {[/size]
[size=4]if (req.status == 200) {
alert ( "Not able to retrieve description+"+req.responseText );
parseMessages();
} else   {
alert ( "Not able to retrieve description+"+req.responseText+"vide" );
}
}
}
function parseMessages() {
response  = req.responseXML.documentElement;
itemDescription = response.getElementsByTagName('lastname')[0].firstChild.data;
alert ( itemDescription );
}
</script>[/size]

[size=4]</head>
<body>
<button onClick="getDescription()">Ajax call</button>
</body>
</html>

it returns req.status = 0!!

Link to comment
Share on other sites

×
×
  • Create New...