CodeIgniter Forums
Ajax with a custom template - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: Ajax with a custom template (/showthread.php?tid=44095)

Ajax with a custom template - El Forum - 08-03-2011

I just wanted to say how much I appreciate the is_ajax_request() method. It makes progressive enhancement a cakewalk with ajax calls:

if($this->input->is_ajax_request()) {

            } else {
                $data = array(
                    'title'     =>  'Sign up for News and Info',
                    'main_content'   =>  'signup_success'
                $this->load->view('template', $data);
I have a template that loads header, sidebar, and footer dynamically:

<div id="container">

        &lt;?php $this->load->view('layout/header'); ?&gt;
        <div id="main-and-sidebar" class="clearfix">    
            <div id="main" role="main" class="left two-thirds clearfix">
                <section id="content">
                    &lt;?php $this->load->view($main_content); ?&gt;
            &lt;?php $this->load->view('layout/sidebar'); ?&gt;
        &lt;?php $this->load->view('layout/footer'); ?&gt;

With jquery I can clear the content and replace with the response from the server:
/*      Signup form         */
    $('#signup-form').submit(function(e) {
        var email = $('#email').val()
        var loading = $('<img class="noshadow" src="/img/loading.gif">');
        $.post('signup', {
            'email' : email
        }, function(response){
        return false;