I have phonegap and jquery mobile working properly and am trying to add codeigniter into the picture. I’m thinking there might be a few ways of doing this to send/receive data. I’ve searched for such a question and read the codeigniter nettuts tutorial but am still confused to make it work with phonegap.
For an example, to help explain, lets assume I’m trying to receive an array of objects that stores 3 fields, id, articleheadline and article.
Article System -Table fields
id
articleheadling- text
article
$.ajax({
url: 'http://www.server.com/controllername/method/id',
success: function( data ) {alert('add to view'); }});
Can i use a .ajax post call to a controller like (http://www.server.com/controllername/method/id) and load it into a div using a json returned var from php to js where the array or objects is added to the view( i.e. screen) or should I have the ajax call return a partial html thats processed on serverside to the view. I’d really appreciate any examples , I’ve also saw an example I think I can use here
<?php
$jsonurl = "http://search.twitter.com/trends.json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
foreach ( $json_output->$articles as $article )
{
echo "{$article->$articleheadline}\n";
} ?>
the url in the above example is from the original. but if I tried something like that what would that trends.json file look like?
I hope this wasnt too long but I tried my best to split up my questions.
Thanks
For use with phonegap, I’ve tried this approach:
Use jQuery Mobile and save mustache templates in your phonegap application. Then use jquermobile to request json data from the controller, and load the response in the mustache template. This will require you to hack the jquery mobile library to support mustache templates and reading/populating template files.
In the above, your codeigniter application is essentially acting as a REST API that returns a json response, which contains data to load in the mustache template, the template file to load, and any error messages or such to display. The phonegap+jquerymobile setup is dumbed down to handle navigation and page rendering only. Each link the application maps to an api url that jquerymobile calls via ajax automatically.