Request
The Request library consists of a CodeIgniter library to determine whether a request has been made via AJAX. The Request library makes it very easy to stick to DRY principles and utilize the same controller methods for all of your users, even if Javascript is disabled.
Usage
The request library only features one method, is_ajax() which returns a boolean if the current request was sent via AJAX.
$this->load->library('request');
if ($this->request->is_ajax()) {
$this->load->view('ajax/view', $vars);
} else {
$this->load->view('normal/view', $vars);
}
License
This project is licensed under the GNU-LGPL with the following addendums that override, or explain in further detail, any statements found within that license:
- You may use this library as part of any commercial/derivative work.
- You are not required to license your commercial/derivative work under the GNU-LGPL.
- You are not required to provide the source code for this library if your commercial/derivative work is compiled.
- You must include an unmodified, readily available, version of this library’s readme file within all releases and derivative works.
Download
If you found this tutorial helpful, please consider donating via Paypal.

Brilliant
I owe you for creating this library!
Normally I would create two separate functions in my controllers to do exactly the same thing: One for AJAX-calls responds in XML and another which responds with a normal (XHTML) view.
Your library gave me a much better solution…thnx!
@Jakob
Glad it could help - feel free to share the link with others!
Nice script, but I really don’t think it needs to be a library. A helper function is a good idea, but a library? No.
@Jamie
I have future plans for this that will require it to be a library. Well, not require but it just makes sense. No need to transition from helper to library later in this package’s lifecycle.
Oh, Ok!
I just thought that such a simple script (A line of code) doesnt need the overheads that using OO-PHP and CI requires.
What sort of plans do you have?
Thanks for that explanation about why you chose to make it a library - I was wondering the same thing!
Great!! thanks Michael, I just started CI and was wondering how to make one function work for both normal and AJAX request. I was going to make 2 separate functions (:-P) until I found your library.
The code is simple, but the important thing is the idea, good idea Michael
hey bro, this looks interessting, should be integrated into CI