Reputation: 11
Plz help,
I am simply calling the Rest Based Web-Service in my new PhoneGap App for Iphone.
I am using the XCode 3.2.3 in which I have installed the PhoneGap framework and it works fine.
Developed a simple javascript code which uses the AJAX. Below is the code.
THis code works fine the in:
IE, Morzilla and Safari Browser of my Mac Pc also on
Safari browser of the Iphone Simulator but when I integrate this code in my PhoneGap app's index.html
in www folder it doesn't give any response.
<html> <head> <script language="javascript" type="text/javascript"> function callingRestBasedWebService() { alert('In callingRestBasedWebService'); var username = document.getElementById('usernameid').value; var password = document.getElementById('passwordid').value; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var responseXML = xmlhttp.responseText; alert("ResponseXML="+responseXML); if (window.DOMParser) //Creating DOM Object for Morzilla for parsing XML { parser=new DOMParser(); xmlDoc=parser.parseFromString(responseXML,"text/xml"); } else // Internet Explorer // Creating DOM object for IE for parsing XML { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(responseXML); } x=xmlDoc.getElementsByTagName("Login"); if(x[0].getElementsByTagName("status")[0].childNodes[0].nodeValue == 'Success') { alert('Login Successfull'); }else { alert('Login Failed'); } } } xmlhttp.open("GET","http://pc-a401115.patni.com:8080/BankWebService/resources/validateLogin?username="+username+"&password="+password,true); xmlhttp.send(); } </script> </head> <body> <br><br> Username : <input type="text" name="username" id="usernameid"><br><br> Password :<input type="text" name="password" id="passwordid"><br><br> <input type="button" name="Login" value="Login" onClick="javascript:callingRestBasedWebService();"> </body> </html>
Could someone help me out, and plz inform if I am wrong some where..
Thanks, MobileAppMaster
Upvotes: 1
Views: 1493
Reputation: 1
If you use the latest version of phonegap, insert after head:
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js">
</script>
Upvotes: 0
Reputation: 7985
since "pc-a401115.patni.com" has no dns record I suspect that your iphone can not resolve the hostname which should lead to a very long timeout (properly one minute with phonegap)
Try using the ip address of your webserver instead.
Upvotes: 0