I'm wondering if anyone has any advice regarding using PhoneGap to send and receive information from a web server. Is there a standard way of doing this? Any best practices? I'm pretty new to app development and any advice would be helpful.
Thanks
I personally use jQuery ajax. The awesome thing about phonegap and running js on a phone is that you have no normal javascript security issues like crossdomain issues.
One thing you need to remember is that in order to reach outside servers you will need to add a new key to your plist in your external hosts KEY: websites VALUE: *
the * is a catch all so any domain can be accessed.
as for the ajax treat it like a normal ajax request:
$.ajax({
url:'http://your-url.com/script.php',
type:'post',
data:'arg=foo&argB=bar',
success:function(data){
console.log(data);
},
error:function(w,t,f){
console.log(w+' '+t+' '+f);
}
});
good luck happy deving!
I've got a few phonegap tutorials on my blog - http://www.drewdahlman.com/meusLabs/
Use any AJAX you want.
Remember to allow the server you're going to communicate in your config.xml file!
<access /> - deny all
<access origin="*" /> - allow any
<access origin="http://example.com*" subdomains="true" /> - allow all of example.com
There are more examples in the config.xml file.
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