phonegap with codeigniter backend phonegap with codeigniter backend codeigniter codeigniter

phonegap with codeigniter backend


First of all, lets get your example running, your post data is json, and the datatype is json but your CI implementation is accessing post variables.

The quick and dirty fix is to submit a uri string in the post data such as:

&headline=test%20headline&article=test%20article

This can be generated from a form with the jquery serialize function:

var myData = $('#form-id').serialize();

This post data will be set in the $_POST var on submission and then later accessible through the CI post function:

$this->input->post()

*Note: remeber to remove the dataType setting in the ajax call for this to work.

For a more politically correct way to solve this problem, you're going to want to leave your javascript alone (thats all good) but you need to set the CI backend up as a RESTful service, the default installed controller and input classes won't handle it. You need to use something like Phil Sturgeon's REST implementation:

  • There is a github project for the code,
  • A blog post (read this first - its a good short primer on REST servers for CI concerned usage),
  • And the tutorial you already know about.
  • Oh and a video on setting it up.