Skip to content

AJAX for CodeIgniter

Derek Jones edited this page Jul 5, 2012 · 21 revisions

Category:Library::Community | Category:Library::AJAX

AJAX for CodeIgniter is a CodeIgniter library that provides you with AJAX functionality for your CodeIgniter web applications. It comes with simple to use AJAX helpers that you can directly put in use in your apps.o AJAX fr CodeIgniter includes both Prototype and Scriptaculous helpers. This is compatible with CodeIgniter 1.5.1.

Download: File:AJAX-for-CodeIgniter.zip

Download: File:AJAX-for-CodeIgniter_v2.zip (with fixed bug)

Below is a quick and simple how-to-use article. For code references and full class documentation, please read the full user guide that comes with the zip file (follow the above link to download).

Enjoy this release.

  • siric

How to use AJAX for CodeIgniter?

Place the AJAX library in the following directory (default libraries directory):

www-root/system/libraries/

Place the javascript files in your www root directory. For example:

www-root/javascript/

If you use mod_rewrite, make sure you allow the javascript directory to be accessed. To do this, set up your .htaccess file to look something like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|javascript)
RewriteRule ^(.*)$ /index.php/$1 [L]

Then, simply include whichever javascript files you would like to use in your html file:

<script src="javascript/prototype.js" type="text/javascript"></script>
<script src="javascript/effects.js" type="text/javascript"></script>
<script src="javascript/dragdrop.js" type="text/javascript"></script>
<script src="javascript/controls.js" type="text/javascript"></script>

Finally, load up the AJAX library as you would with any other CodeIgniter library. There are two possible ways to do this. Directly from within your controller:

$this->load->library('ajax');

Or, auto-load the AJAX library from within system/application/config/autoload.php:

$autoload['libraries'] = array('database', 'session', 'ajax');

Then all you need to do to use an AJAX helper is to call $this->ajax. For example:

echo $this->ajax->link_to_remote("Login", array('url' => '/login', 'update' => 'divblock'));
Clone this wiki locally