Sam Croft

A designer/developer on HTML, CSS, JavaScript and PhoneGap

Posting data from a PhoneGap app to a server using jQuery

  • 83 comments

Filed in: android, forms, iOS, jQuery, MySQL, PhoneGap, php

Recently I’ve had several requests to create an article about posting data to a server from a PhoneGap app so I thought I’d cover the steps I go through when dealing with this kind of requirement.

The method is extremely simple providing a few important steps are followed.

Important: Although not necessary, the context of this article will be better understood if you have read my previous article, Updated: loading external data into an iOS PhoneGap app using jQuery 1.5.

The reference to landmarks throughout this article refers to a barebones app I created in the aforementioned article where I was listing the geo-coordinates of several well known UK landmarks.

Creating an iOS PhoneGap app with Xcode 4

The first step is to create a new iOS PhoneGap app. Open the project location in finder, create your www folder and add it to the project in Xcode. You will also need the phonegap.js file if one isn’t already built when you compile. Make sure you use the corresponding version for your version of PhoneGap—I’m using phonegap-1.2.0.js.

Although I’m using iOS as the example, the project www files would be the same for Android and indeed any other supported platform.

Creating the form to post data from

Continuing with the example I created in my article about loading data from a server in a PhoneGap app, where I was loading geo coordinates for a few famous UK landmarks, I can expand on this and add a form for each landmark to submit data back to the server.

A simple comments form

I’m going to use a really simple form for each landmark so users can leave a comment about it.

<div id="landmark-1" data-landmark-id="1">
	<form>
		<label for="email">
			<b>Email</b>
			<input type="email" id="email" name="email">
		</label>

		<label for="comment">
			<b>Comment</b>
			<textarea id="comment" name="comment" cols="30" rows="10"></textarea>
		</label>
		
		<input type="submit" value="Save">
	</form>
</div>

I have used my preferred method of form markup.

Note: the intended use of this markup is that it is generated, or at least made visible, when a user taps an ‘add comment’ button. When this function is called the id for the landmark the user is commenting on is in the parent div as an id and custom data attribute. It could also be a hidden form field, but seeing as the id for the landmark is already available this seems unnecessary bloat.

How you go about integrating this is entirely based on your app and what fits best, I am merely mentioning what fits best with my landmarks app.

Using jQuery to handle and post form data

As with my previous articles I’m going to use jQuery for the JavaScript library but it’s worth mentioning that something like xui.js may be more suitable if you’re trying to create an app with as small a footprint as possible.

Using the .submit() event handler

While not necessary, it’s certainly considered correct to use jQuery’s .submit() event handler rather than an HTML button or link when dealing with forms.

A basic function assigned to the .submit() event handler:

$('form').submit(function(){
	var landmarkID = $(this).parent().attr('data-landmark-id');
	var postData = $(this).serialize();
	
	$.ajax({
		type: 'POST',
		data: postData+'&amp;lid='+landmarkID,
		url: 'http://your-domain.com/comments/save.php',
		success: function(data){
			console.log(data);
			alert('Your comment was successfully added');
		},
		error: function(){
			console.log(data);
			alert('There was an error adding your comment');
		}
	});
	
	return false;
});

There are three important things going on in this function:

Line 2: firstly, I am grabbing the id for the landmark that is being commented on. I’m accessing this value from the custom data-landmark-id attribute in the parent div element.

Line 3: secondly, I am using jQuery’s serialize() method to gather all the data and values from the form. This is somewhat easier than stepping through each field and using the val() method. If I was to log the postData variable the output would be something like; email=me@site.com&comment=I like this location!

Lines 5-15: finally, I am using jQuery’s ajax() function to POST the data to a server. A successful POST will trigger one function while an error will trigger another.

This is the foundation for posting form data from a PhoneGap app.

Note: if you are creating your forms on-the-fly then you will need to use the live() event handler with your submit() event handler.

Using PHP to create a server-side component to store the data

My previous article about loading data from a server used PHP and MySQL so I’m going to continue with the same example and build on the database.

Creating a table to store the comments

First I’m going to create a small table that will contain all of the submitted comments.

CREATE TABLE `comments` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `location_id` int(11) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `comment` text,
  PRIMARY KEY (`id`)
)

This is fairly self explanatory. I’m going to store the email address, comment and the location id.

Creating a tiny PHP script to handle and store the comments

The next part of submitting a comment is to create a PHP script that takes the data from the app, sanitises it and stores it in MySQL.

$server = "";
$username = "";
$password = "";
$database = "";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());

mysql_select_db($database, $con);

$locationID = $_POST["lid"];
$email = mysql_real_escape_string($_POST["email"]);
$comment = mysql_real_escape_string($_POST["comment"]);

$sql = "INSERT INTO comments (location_id, email, comment) ";
$sql .= "VALUES ($locationID, '$email', '$comment')";

if (!mysql_query($sql, $con)) {
	die('Error: ' . mysql_error());
} else {
	echo "Comment added";
}

mysql_close($con);

Lines 1-4: set up database connection details.

Lines 6 & 8: connect with the MySQL server and select the database that will be used.

Lines 10-12: grab the POSTed form data from the PhoneGap app and sanatise any strings.

Lines 14-21: create a string with an SQL insert query and then execute the query. Return a success or error message.

Line 23: close the MySQL connection.

Testing the app in the iPhone simulator

The final step is to build and compile the app and see how it works in the iPhone simulator. Bear in mind a couple of things and a common oversight and you’ll be submitting data to your server with no problems.

An iOS PhoneGap app showing the confirmation message of a comment being sent to a server
If all goes well, you should see this alert box when you submit a comment.

Console logging is your friend

You’ll notice in the js function that I have a couple of console.logs that return the status of the comment save. These are great when you’re testing in your browser as you can see them in the developer console. And they also appear in the Xcode debug console (shift+cmd+c), so use them to step through your code if you are having issues.

Add your server to your app’s server whitelist

With PhoneGap 1.0 came the addition of server whitelists whereby you must declare any external hosts that you will be accessing data from or sending data to.

To add your server as an external host; view the PhoneGap.plist in Xcode (project navigator > project > supporting files) and add a new item within the ExternalHosts array for your server. In this example I’m using localhost so I’m going to go ahead and add a string value of localhost.

Because I’m using localhost I’m also going to add another string value – debug.phonegap.com. This explicitly states I am in debug mode, rather than release.

If I was using my own website as a data server I would add a string value of samcroft.co.uk and drop the debug.phonegap.com value.

This is just the basic outline

One final note is that this is just the basic outline in submitting data to a server from a PhoneGap app. Utilising this further you would have to consider how best to integrate with your app, create client and server side validation, have loading gifs, visually handle a complete form submission and maybe trigger a function that gathers the new data and appends it to any existing data already visible. I will cover all of this in another article if there is any interest.

About the author

I'm Sam Croft - a thirtysomething designer/developer and co-founder of Running in the Halls Ltd—a web and app development studio in Huddersfield, UK. I was educated in graphic design and now specialise in front-end web and app development; my main passion being usability and accessibility. I strongly believe web apps (vs native) are the future and love developing for mobile using the wonderful PhoneGap.

I am a massive sports fan - Formula One in particular. I live in the Pennines with my beautiful wife, Alex. Occasionally I own a large scruffy beard.

I tweet about all of my interests - you should follow me. I also have a .

  • http://twitter.com/chriskemm Chris Kemm

    Great post! Might be a stupid question as i’ve quickly read it, but can you post data via https with this method. 

  • Sam Croft

    Should work absolutely fine, Chris. Not tried it with POST but works OK with GET.

  • Sam Croft

    And thanks for the kind words :)

  • Pingback: Updated: loading external data into an iOS PhoneGap app using jQuery 1.5

  • asics64

    How about including image ?can i use the same method ?

    E.g (sending email,comments and image to the remote sql svr)

  • Anonymous

    This is entirely possible yes.

    See: http://wiki.phonegap.com/w/page/18270855/Image%20Upload%20using%20JQuery%20and%20Python

    And: http://zacvineyard.com/blog/2011/03/25/upload-a-file-to-a-remote-server-with-phonegap/

  • asics64

    Hi Sam, Thank for your advice. But i am current using: SQL Server and asp on server side. 

    And i intend to send, email,comments and image together to my sql server via asp. But the save button does not seem to trigger the form function

  • asics64

    do you have advice on this kind of work around? I does not seem to get the data to my remote server

  • Anonymous

    What kind of error are your receiving if you run this in your browser and check the console?

  • asics64

    i finally got to post the image over to the server. I saw that we can add in optional parameter as well. But how does we see that in the php ?

  • http://samcroft.co.uk/ Sam Croft

    In your php you could try

    var_dump($_POST);
    This will return an array of all of the $_POST variables. It’s a good way to debug if you’re posting a lot of things, rather than stepping through each one on at a time.

  • Jayeshnmbr

    Hi sam

    congratulations for the great post. i have a small doubt here.
    i am trying to develop small windows mobile app to upload images from
    the phone to my remote server, and i am using windows phone sdk 7,phone
    gap and jquery.now i am trying to upload images using php script.writh
    now i am able to access the camera and library but cant upload the
    file.please help me

    thanks

  • Adam Reimer

    Quick question: Is it possible to remove the “index.html” line from the top of the alert? I’d rather my users not see that

  • http://samcroft.co.uk/ Sam Croft

    Yes, it is. The method above was just a quick and easy way to demonstrate it working and ensure you would be able to test it in a browser.

    For production you can use the PhoneGap notification alert function, which fires off a native alert http://docs.phonegap.com/en/1.0.0/phonegap_notification_notification.md.html

  • Craig

    Another great quick tutorial, thank you Sam.  Works like a charm.  Any time to show a simple validation of the form fields and redirection if form field posts match a database entry, such as email / password?  Thanks!

  • http://samcroft.co.uk/ Sam Croft

    Thanks Craig. I’ll certainly cover those aspects in a future article.

    Have you considered using HTML5 validation? It’s pretty cool what you can do with it: http://blog.mozilla.com/webdev/2011/03/14/html5-form-validation-on-sumo/

    http://www.w3.org/TR/html5/forms.html#client-side-form-validation

  • Pingback: I T | Pearltrees

  • http://www.facebook.com/edadez Rober Dote

    Sam,

    thnks 4 this post.
    I have a problem…
    When i press submit button, index.html is refresh. and mysql is empty.
    i try in web browser, and in ‘url bar’ show some like this –> http://www.myserver.com/guarda.php?dato1=xxx&dato2=yyy
    and my database is empty :(

    Any help please :)

    (sry 4 my english.)

  • Gmeyers

     Same problem here… but it works on macBook Safari. Any Ideas?

  • http://samcroft.co.uk/ Sam Croft

    Some questions:

    When you are testing in the browser – are the js and php files on the same domain? It will not work cross-domain unless it is from within your PhoneGap app.Open the developer console in your browser and see if there are any errors in the console log. Also, check the network tab and see if the php file is being called correctly. This should help you determine what isn’t working.Let me know what happens.

  • http://samcroft.co.uk/ Sam Croft

    So it works in Safari, but not in your PhoneGap app?

    Are there any error messages in the Xcode console log?Did you add your domain to the server whitelist in your app plist?

  • Gmeyers

     GOT IT! my whitelisted domain was being rejected for some reason. I found this article here http://www.prosoxi.com/2011/10/08/xcode-phonegap-white-list-rejection/ Need to add this to the whitelist entry *.mydomain.com Thanks for the post. The best tutorial on the entire web… I’ve looked at them all I believe. CHEERS!

  • Geetha

    When testing this app i got the following error
    PostData2Server[1006:13403] [INFO] Error in success callback: NetworkStatus0 = TypeError: ‘undefined’ is not an object
    Please help me to solve this

  • http://samcroft.co.uk/ Sam Croft

    What version of PhoneGap/Cordova are you using? 

    I think you might be having a conflict with jQuery and the onDeviceReady function. Try this method of how to use jQuery with PhoneGap http://www.neotericdesign.com/blog/checking-the-online-status-with-phonegap-jquery

  • Ettore Manetti Ink

    a genius, as always

  • http://samcroft.co.uk/ Sam Croft

    Too kind, thank you!

  • Ganesh

    could you suggest me  the code for connecting the server  for android in phonegap ?please..

  • http://samcroft.co.uk/ Sam Croft

    The HTML, JS and PHP would all be the same for an Android app. The only thing different would be PhoneGap project itself. 

    I will try and update the Git repository so that it includes and Android version as well, when I have some time. 

  • Nagella Ranjith

    Hi Sam,
    I followed your tutorial and i hope it’s same for cordova based applications. I used cordova 1.8.0.js file instead phone gap-1.2.0.js file. But when i submit the comment there is no action taking place. I m not seeing any console error. and more over when i am running a prompt box is opening and it is “Dveloper Tools Access needs to take control of another process for debugging t continue. Type the name and password of a user in the “Developer Tools” group to allow this.”.

    is the above prompt making demo not working ??

    Thanks & Regards
    Ranjith

  • Nagella Ranjith

    Hi Sam, I figured out the problems. Thanks any way..!!

  • http://samcroft.co.uk/ Sam Croft

    Glad you sorted it, Nagella. You should share how you fixed it – someone else might have the same issue.

  • Puneet

    Hi Sam 

    Can You Provide some help on sending images to amazon s3 using phonegap

  • Silko

    Sam thanks for the great post. Are we able to also post Geolocation information as well and would we place this like the landmark ID ?

  • Madhulika

    Hi!
    I have researched everywhere and found that apparently Phonegap cant process php.
    However here you have used php.
    I want to know how does one post data to a server (say, localhost, on my pc) from a phonegap web application using json?
    Your previous article was about loading data from a server using json, but i want to know how to ‘post’ the same. As in how to INSERT INTO table … etc using json.
    Thank you.

  • Madhulika

    Also, i found that the php file needs to be hosted on a server to be able to be processed by phonegap.
    I dont know how to do that. How do i make localhost (im using xampp) ‘host’ my .php file?
    I will ab really glad if you could help. :)

    Great tutorial by the way!

  • ranjith kumar
  • http://samcroft.co.uk/ Sam Croft

    Hi Madhulika,

    This article is all about posting data from a PhoneGap app to a server. It covers each step.

    - Sam

  • http://samcroft.co.uk/ Sam Croft

    If you’re using XAMPP (I use that too), then make sure Apache and MySQL are running, create a directory in your xampp > htdocs folder and place the php in there. Edit the settings to make sure everything is right for your setup. Create the database using the SQL code above and you’re set to go…

  • Madhulika

    Thank you so much!! :)

  • Madhulika

    Yes it is helpful indeed.
    Thank you very much for taking time. :)

  • ranjith kumar

    Its Great..!! It was my first post ever. Thank you so much for your appreciation.

  • http://samcroft.co.uk/ Sam Croft

    Hi Silko,

    Absolutely. This would be quite straightforward, you just need to hook into PhoneGap’s Geo Location object - http://docs.phonegap.com/en/1.0.0/phonegap_geolocation_geolocation.md.html#geolocation.getCurrentPosition

  • David Hernández

    is possible to have a form where I can upload images to my mysql database?. 

    Thanks

  • Francis

    Hi Sam

    Very nice tutorial. I seem to lack the needed skills though. I could set up all the hings all right and when I post the form nothing happens the page just sweeps to the left and reloads, but no alert shows up. Here what I did: I just added the function in a tag within the same page as the form in the header tag. Yet the function doesn’t sem to be called at all. Stupid question: Do I have to create an external js file for the function an include it? shouldn’t make a difference right).

    Thanks for help
    Francis

  • Francis

    Hi Sam, I could resolve it. It was a stupid character transformation issue when copy/pasting your code > the single/double quotes around the $(“form”). function part. It now works like a charm.

    Cheers
    Francis

  • http://samcroft.co.uk/ Sam Croft

    Hi Francis,

    Glad you managed to sort this. Let me know if you run into any further issues.

    - Sam

  • http://www.facebook.com/simonpn Simon Pettersen Nguyen

    I have the same problem. It’s won’t work with cordova.

  • http://www.facebook.com/simonpn Simon Pettersen Nguyen

    Hi!
    Like Nagella Ranjith said, I does not work with Cordova. Do you have a fix?

  • ranjith kumar

    Hi Simon, I used one of my lab computer, where I don’t have access to developer tools which I sort with the help of my Administrator. The problem was I don’t have access to developer tools, the system administrator has to login with his credentials. This way you can sort the above problem.
    Thanks!!
    Ranjith

  • Arpit

    Hey Can I use the
    http://localhost:8081/pgap/index.htm type of url string while connecting via Android emulator….!!!please help me ……

  • Pingback: My article for Adobe’s Appliness magazine: Loading data into, and posting data from, a PhoneGap app

  • Rob

    Hi Sam, wonderful post, I have found this article and the article about loading data from a mysql database into a phonegap app extremely helpful. I do have a problem however, and I wonder if you could help me. I am trying to post a search query to my database from phonegap and here in this demo you use the INSERT command. How can I get this to work with the search command? What I mean is, how do I search my database from a form and then display the results gathered using JSON. Any help would be greatly appreciated. Keep writing.

  • http://www.facebook.com/basco.johnkevin John Kevin Marbella Basco

    Thank you very much!

  • marc

    y u not use facebook?

  • tomassi

    i got: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”’,”)’ at line 1

  • thomas

    problem was that $locationId did not have ‘ ‘ quote marks >>> “VALUES(‘$locationID’, ‘$email’, ‘$comment’)”;

  • http://samcroft.co.uk/ Sam Croft

    Hi Thomas,

    This could have been because your locationid field in your database was not an INT. If it is a varchar it would need quotes yes, as it would be expecting a string. An INT column would not require quotes. Maybe that was the issue here?

  • Pingback: Phonegap Tutorials « PHPsolutionBD

  • Rajanikanth

    Really good ……

  • harsh sharma

    nice article, can you please post some more articles, create client and server side validation, have loading gifs, visually
    handle a complete form submission and maybe trigger a function that
    gathers the new data and appends it to any existing data already visible.

  • Chris J.

    Thanks Sam for posting this. I has really helped me! I have run into a problem that I can’t seem to figure out, I am sure I am doing something wrong on my end. I have followed the steps above but when I submit my form it just refreshes the page. I do not get a success or fail notification. I have specified my server in the .plist file. I have also tested my server file which connects to the db and that works fine. Since I do not get a message when I submit I assume that my error is in the form or function before it even tries to access the file on the server.

  • http://samcroft.co.uk/ Sam Croft

    Hi Chris,

    Are you seeing anything in your javascript console (if testing in browser) or in xcode’s console? If you’re using the iPhone simulator you can open Safari and then debug your application with Safari’s debug tools (see http://stackoverflow.com/a/12583684).

    This should highlight what is going on…

  • Chris J.

    No errors are coming up in Xcode or in Safari. I am running the iPhone simulator 6.0. Would it make a difference whether the function is called from an external page or on the same page as the form? I wouldn’t think so but just being sure. Thanks so much for your help!

  • Chris J.

    Doh, I forgot to add the body onload. It is working now. I feel silly. Thanks for the great tutorial Sam.

  • http://samcroft.co.uk/ Sam Croft

    Easily done. Glad it’s all working now :)

  • wahdan kedai

    is it possible to use the script for android apps?

  • http://samcroft.co.uk/ Sam Croft

    Hi Wahdan,

    Absolutely. This is why PhoneGap is so good, you write the same HTML and JavaScript and use it on different devices.

  • phil1983

    Hi Sam,

    found your blog searching for “phonegap form validation”. Thanks for your article. I’m new to phonegap and it really helped me.

    In “This is just the basic outline” you offered to write another article with detailed form validation, loading gifs, ….

    Did you write the offered article?

    Greetings from Germany.

  • http://www.facebook.com/stuart.westgate Stuart Westgate

    Hi Sam

    Firstly thanks for taking the time out to write this :-0

    I’ve tried implement my own version of this but something is wrong and I’m not sure what. I no my database is working but the code from my form doesn’t seem to be getting through.

    Can you give me some advise please.

    I think it’s something wrong with the javascript side of things but I have know idea what.

    Please help

    This is my index.html form that I want to send: (Clientside)

    Phone Number

    First Name

    Last Name

    Current Date

    Current Time

    This is the post.js script I’m using to send the form: (Clientside)

    i$(document).bind(‘deviceready’, function(){
    $(function(){
    $(‘form’).submit(function(){
    var sendData = $(this).parent().attr(‘sendInfomation’);
    var postData = $(this).serialize();

    $.ajax({
    type: ‘POST’,
    data: postData + ‘&lid=’ + sendData,
    //change the url for your project
    url: ‘http://www.stuartwestgate.co.uk/final_project/save.php’,
    success: function(data){
    console.log(data);
    alert(‘Your comment was successfully added’);
    },
    error: function(){
    console.log(data);
    alert(‘There was an error adding your comment’);
    }
    });

    return false;
    });
    });
    });

    and this is the save.php script (Serverside):

    $phoneNumber = mysqli_real_escape_string($_POST["phoneNumber"]);
    $firstName = mysqli_real_escape_string($_POST["firstName"]);
    $lastName = mysqli_real_escape_string($_POST["lastName"]);
    $currentDate = mysqli_real_escape_string($_POST["currentDate"]);
    $currentTime = mysqli_real_escape_string($_POST["currentTime"]);

    //$sql
    = “INSERT INTO member (phoneNumber, firstName, lastName,
    profilePicture, photo, video, textMessage, callData, activityData,
    latitudePos, longitudePos, currentDate, currentTime) VALUES
    (‘$phoneNumber’, ‘$firstName’, ‘$lastName’, ‘$profilePicture’, ‘$photo’,
    ‘$video’, ‘$textMessage’, ‘$callData’, ‘$activityData’, ‘$latitudePos’,
    ‘$longitudePos’, ‘$currentDate’, ‘$currentTime’)”;

    $sql =
    “INSERT INTO member (phoneNumber,firstName, lastName, currentDate,
    currentTime) VALUES (‘$phoneNumber’, ‘$firstName’, ‘$lastName’,
    ‘$currentDate’, ‘$currentTime’)”;

    if (!mysqli_query($connection, $sql)) {
    die(‘Error: ‘ . mysqli_error($connection));
    } else {
    echo “Comment added”;
    }

    mysqli_close($connection);
    ?>

  • hardsolidman

    i have an android project… i tried to display data from localhost using json and php, and it work… then i want to insert some additional data using ajax its like
    $(‘#submit’).click(function() {
    $.ajax({
    type: “POST”,
    url: “http://localhost/mysql/save.php”,
    data: {‘form’: $(“#saveForm”).serialize(), ‘other’: extra_data},
    success: function(data)
    but it doesnt work
    any advice…?

  • http://samcroft.co.uk/ Sam Croft

    Only just seen this comment. What errors are you seeing in the console log? Try changing the click event for your submit button to the submit event. $(‘#submit’).submit(function(){…..

  • Jedd

    is this would work on the jquery ajax shorthand methods? (e.g. $.post)

  • Kunchit Surachon

    I send data with ajax() to php file on server same as your code ,but data not send to php file

  • pixel

    Thank you I followed your article and it works fine and inserted data in database, however error function always fired even though( php code succeed in adding data in database).

    I tried to trace the error using firebug, the status is (200 OK), however during processing the ajax I notice the php url in red and status is 407, once it done, the status become 200 OK.

    Using jquery-1.10.2, cordova 2.9.0

  • Alex Christensen

    DO I need to create a table or anything? I’m really confused. I’m building this app in PhoneGap with jquery mobile and trying to connect this to my database and nothing happens.

  • Kiran Kyasa

    What should I do if I want retrieve the data back to the Phonegap app. ??

  • http://soapboxllc.com Paul Crosby

    Thank you so much for posting this! I was looking around all over the internet for info on submitting form values into a database with AJAX and phone gap, and this was the most clear resource on how to do it. I am now up and running. One thing, though: in your PHP section, the following two lines of code are displayed for the SQL insert:

    $sql = “INSERT INTO comments (location_id, email, comment) “;
    $sql .= “VALUES ($locationID, ‘$email’, ‘$comment’)”;

    Shouldn’t it just be this?

    $sql = “INSERT INTO comments (location_id, email, comment)
    VALUES ($locationID, ‘$email’, ‘$comment’)”;

    I’m still kind of new to all of this, so maybe you had a reason for doing that. Thanks again for posting!

  • http://samcroft.co.uk/ Sam Croft

    Hi Paul,

    Glad this has helped you. I’m actually in the process of writing some more up to date versions of these Phonegap articles.

    You’re right about the SQL, it could just be like that. I believe I split it into two lines as there was an issue with the length of code in the preview. But you will see it sometimes, some people (I think it’s a legacy of ASP code) like to separate the values on a separate line. Both ways are absolutely fine.

    Thanks for your comment :]

  • http://soapboxllc.com Paul Crosby

    Got it. Thanks again, Sam!

  • Nehul Agrawal

    Awesome tutorial. It helped very much. But when when i want to fetch data?

  • http://samcroft.co.uk/ Sam Croft

    Thank you, Nehul. Sure – check this article http://samcroft.co.uk/2011/updated-loading-data-in-phonegap-using-jquery-1-5/ it needs updating but the core functions are still the same.

  • Pingback: Using CodeIgniter as the backend for PhoneGap app developing | Portfolio - YOYU

  • Abhishek Gupta

    good post it’s…could you please explain all of the steps included in connecting a phonegap app(for android) to database(from basics)…i’m new to this technology…so i would be obliged if you help me…thanx in advance…