Sam Croft

Full-stack developer

Tutorial: Using PHP’s JSON encode and decode functions to handle data sent to and from your app

  • 7 comments

Filed in: api, apps, JSON, PhoneGap, php

JSON makes dealing with data in your app exceptionally easy and manageable. The best part about JSON is you can look at it and understand it. It’s not like the confusing spaghetti DOM that you get with XML, it’s a lean minimal representation of your data. If you’re dealing with chunks of data in your app, you want to be using JSON.

So while your app will happily eat up all the JSON you can throw at it, you still need to make it in the first place – and/or have a server side app that is capable of reading it. If, like me, you use PHP to handle things on a server then things are pretty straightforward. You can use PHP’s json_encode and json_decode functions. Encode will take your arrays, or objects, and create a JSON string of your data. While decode will take a JSON string, sent from your app, and turn it into an array or object.

(more…)

Quick tip: using HTML5 localstorage to store JSON objects on a device in your PhoneGap app

  • 34 comments

Filed in: android, cordova, iOS, javascript, JSON, PhoneGap

I’ve written a couple of articles about loading remote data into PhoneGap apps (sans framework), but I haven’t mentioned a good little method of storing that data on the device so you don’t need to request it from a server again. This is a quick tip for how you can do that.

Of course, it depends on the type of data that you are loading from your server in the first place. You wouldn’t necessarily want to store data that would be out of date quickly – such as share prices or live sports scores. But there will certainly be times when you want to save the data you’ve just loaded for use at a later time, without having to load it again.

(more…)

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

  • 29 comments

Filed in: android, apps, cordova, iOS, jQuery, JSON, MySQL, PhoneGap, php, zepto

In September we tweeted a photo at RITH of a PhoneGap app we’d been working on. The photo showed the app running on quite a few iOS and Android phones and an iPad. One HTML5 app, running perfectly on many devices, all with different resolutions and pixel densities.

UniApp running on iPhone and Android phones and an iPad

Following a retweet by PhoneGap we were contacted by Adobe’s new magazine, Appliness, to see if we’d like to write an article for their October issue. I jumped at the chance.

(more…)

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

  • 195 comments

Filed in: iOS, jQuery, JSON, MySQL, PhoneGap, php

Update: Following the release of PhoneGap 1.0 and XCode 4 I have updated the Git repository to include a version built with PhoneGap 0.9x (the original version) and a separate version for PhoneGap 1.xx+.

Update: Due to some issues with the recent versions of Cordova I have updated the Git repository to also include a version built with Cordova 1.7.0.

My 2010 post about loading data into a PhoneGap application is by far the most viewed page of my blog so I thought I’d revisit it and write an article about a more efficient method I have been using, following the release of jQuery 1.5.

Previously I had been using the wonderful JSONp jQuery plugin because jQuery 1.4 and lower did not support out of the box error handlers for JSON requests. jQuery 1.5 does, however, and it’s made things simpler and more streamlined.

(more…)

Loading external data into a PhoneGap app using the jQuery JSONP plugin for cross-domain access

  • 45 comments

Filed in: jQuery, JSON, PhoneGap

Important: view updated article – 9th July 2011

Following the release of jQuery 1.5 I have written a more up to date article and made available all of the source code and sample app.

View the updated article

Continuing my love affair with PhoneGap I thought I’d share a few methods of handling external data that I’ve adopted, tweaked and re-written for use in my web app escapades at RITH.

PhoneGap doesn’t ship with a data layer but as web apps [commonly] utilise a JavaScript library, this isn’t an issue. I use jQuery, but it is worth noting there are several other more compact JS libraries that may be more suitable if you want to keep your app as lightweight as possible.

This isn’t solely related to PhoneGap apps – this technique can be used in any web app, but it’s immensely useful within PhoneGap.

(more…)