aminesrine Posted February 22, 2012 Share Posted February 22, 2012 Je veux récupérer des données de webservice prestashop qui renvoie xml. J'utilise PhoneGap pour Android. J'ai essayé ce code, il me donne une bonne résultat sur InternetExplorer (en faite req.status = 200) , mais pas sur mon application PhoneGap (req.status = 0!!!!). <!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> <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> <script type="text/javascript"> function getDescription() { var url = 'http://localhost/prestashop/api/customers/2'; req = new XMLHttpRequest(); req.onreadystatechange = processRequest; req.open("GET", url, true); req.send(null); } function processRequest() { if (req.readyState == 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> </head> <body> <button onClick="getDescription()">Ajax call</button> </body> </html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now