[英]Not able to call REST based web-service using AJAX(simple javascript) in PhoneGap for IPhone
請幫助
我只是在新的iPhone版PhoneGap應用中調用基於Rest的Web服務。
我正在使用XCode 3.2.3,其中已經安裝了PhoneGap框架,並且工作正常。
開發了使用AJAX的簡單javascript代碼。 下面是代碼。
該代碼可以在以下環境中正常工作:Mac PC的IE,Morzilla和Safari瀏覽器也可以在Iphone Simulator的Safari瀏覽器中使用,但是當我將此代碼集成到www文件夾中PhoneGap應用的index.html
中時,它不會給出任何響應。
<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>
有人可以幫助我嗎,請在某些地方告訴我是否有誤。
謝謝,MobileAppMaster
由於“ pc-a401115.patni.com”沒有DNS記錄,我懷疑您的iPhone無法解析主機名,這將導致非常長的超時(使用phonegap大約一分鍾)
請嘗試使用您的網絡服務器的IP地址。
如果您使用最新版本的phonegap,請在頭后面插入:
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js">
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.