Skip to content

AJAX for CodeIgniter

World Wide Web Server edited this page Jul 4, 2012 · 21 revisions

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. AJAX for CodeIgniter includes both Prototype and Scriptaculous helpers. Compatible with CodeIgniter 1.5.1.

Download: File:AJAX-for-CodeIgniter.zip

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

[h3]How to use AJAX for CodeIgniter?[/h3]

Place the AJAX library in the following directory (default libraries directory): [code]www-root/system/libraries/[/code]

Place the javascript files in your www root directory. For example: [code]www-root/javascript/[/code]

If you use mod_rewrite, make sure you allow the javascript directory to be accessed. To do this, set up your [i].htaccess[/i] file to look something like this: [code]RewriteEngine on RewriteCond $1 !^(index.php|images|stylesheets|javascript) RewriteRule ^(.*)$ /index.php/$1 [L][/code]

Then, simply include whichever javascript files you would like to use in your html file: [code] <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> [/code]

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: [code]$this->load->library('ajax');[/code]

Or, auto-load the AJAX library from within [i]system/application/config/autoload.php[/i]: [code]$autoload['libraries'] = array('database', 'session', 'ajax');[/code]

Then all you need to do to use an AJAX helper is to call [i]$this->ajax[/i]. For example: [code]echo $this->ajax->link_to_remote("Login", array('url' => '/login', 'update' => 'divblock'));[/code]

Clone this wiki locally