Connecting to an HTTP Server via Phonegap

I have a server component that connects to a remote server via HTTP and receives some response. Can I connect to similar server code in a java plugin if I use Phonegap for Android?

+7
source share
5 answers

You can use the jmlHttpRequest javascript method to get a response from the server or you can use the jQuery http://jquery.com/ plugin in your application and play with the ajax jquery function.

$.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); } }); 
+3
source

You can use angular '$ http' for such requests.

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

Angular works great with telephony due to its one-page nature.

+1
source

yes you can all you have to do is edit your java file and put in the url of your http request

0
source

Make sure you also provide the URLs you are connecting to (otherwise you cannot connect to the device) ... or if you are using Phonegap Build (build.phonegap.com), which is definitely worth a look if you are just starting, you need to configure the config.xml file.

0
source

You can use the following code in your function: -

  var xmlhttp=new XMLHttpRequest(); xmlhttp.overrideMimeType("application/json"); xmlhttp.open("POST",ipAddress +"/create_account.php",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("email="+emailId+"&password="+password); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { console.log("Registration response: "+xmlhttp.response); var resp = "(" + xmlhttp.response.toString() + ")"; var jsondata=eval(resp); if(jsondata.status == false){ navigator.notification.confirm(jsondata.message,onConfirmOne,'Duplicate Email',['Ok']); }else{ }/*end else*/ }/* end readystate*/ }/*end function */ 
0
source

All Articles