Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to HTTP server via Phonegap

Tags:

cordova

I have server component which connects to a remote server via HTTP(s) and gets some response. Can I connect to such a server side code in a java plugin if I am using Phonegap for Android ?

like image 634
Ved Avatar asked Mar 07 '11 12:03

Ved


2 Answers

You can use xmlHttpRequest method of javascript to get the response from server or you can use jquery plugin http://jquery.com/ in your app and play with ajax function of jquery.


$.ajax({  
   url:'stringURL',  
   beforeSend: function(x) {      
     x.setRequestHeader('Authorization','username/pwd');  
   },  
   dataType:"xml",  
   contentType:'application/xml',  
   timeout:10000,  
   type:'POST',  
   success:function(data) {  
     alert(data);  
   },  
   error:function(XMLHttpRequest,textStatus, errorThrown) {     
     alert("Error status :"+textStatus);  
     alert("Error type :"+errorThrown);  
     alert("Error message :"+XMLHttpRequest.responseXML);  
   }
});
like image 123
Mayur Birari Avatar answered Oct 25 '22 08:10

Mayur Birari


You can consider using angular '$http' for such requests as well.

https://docs.angularjs.org/api/ng/service/$http

Angular works really well with phonegap due to the single-page nature.

like image 1
k.chao.0424 Avatar answered Oct 25 '22 07:10

k.chao.0424