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 ?
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);
}
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With