I am creating a BlackBerry app that provides the functionalities of an already existing web application but making it suitable for mobile phone users. I am creating the mobile app using PhoneGap and leveraging BlackBerry WebWorks SDK. I need to send data to and receive data (submit forms, update profiles) from the mobile app to the server where the web application runs from. I also want users of the app to chat with other users of the mobile app through the BlackBerry Internet Service (BIS). I want the mobile app to be able to query the database already created for the existing web application so existing users who have downloaded the app can view their details on their BlackBerry device instead of their computers. Can someone please recommend a solution?
With phonegap you can send XMLHttpRequests via AJAX. You can do this in pure JavaScript or even easier with jQuery.
You'll need to do the database work with a server-side language, like php.
here's a simple example, assuming you have included jQuery in your Phonegap app.
window.onload = function (){
document.addEventListener("deviceready", deviceReady, false);
}
function deviceReady{
var userName = 'Hans';
var userShoeSize = 'Medium';
$.post("http://example.com/responseHandler.php", {
userName: userName, userShoeSize:userShoeSize},
function(data) {
alert(data.greeting+data.shoeSize);
}, "json");
}
and on the server in responseHandler.php:
<?php
header("Access-Control-Allow-Origin: *");
$response = array();
$response['greeting'] = 'Hi, '.$_POST['userName'];
$response['shoeSize'] = 'Your shoes are size '.$_POST['userShoeSize'];
echo json_encode($response);
?>
By echoing out a JSON encoded string on the server, javascript can easily parse the response. You don't have to use JSON, you can work with anything echoed out on the server.
Just remember to whitelist your page and allow querystrings from other origins on your server.