[eluser]waynhall[/eluser]
I just wanted to say how much I appreciate the is_ajax_request() method. It makes progressive enhancement a cakewalk with ajax calls:
Code:
if($this->input->is_ajax_request()) {
$this->load->view('signup_success');
} 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:
Code:
<div id="container">
<?php $this->load->view('layout/header'); ?>
<div id="main-and-sidebar" class="clearfix">
<div id="main" role="main" class="left two-thirds clearfix">
<section id="content">
<?php $this->load->view($main_content); ?>
</section>
</div>
<?php $this->load->view('layout/sidebar'); ?>
</div>
<?php $this->load->view('layout/footer'); ?>
</div>
With jquery I can clear the content and replace with the response from the server:
Code:
/* Signup form */
$('#signup-form').submit(function(e) {
var email = $('#email').val()
$('article#signup').slideUp();
var loading = $('<img class="noshadow" src="/img/loading.gif">');
$('#content').append(loading);
$.post('signup', {
'email' : email
}, function(response){
loading.remove();
$('#content').append(response);
});
e.stopPropagation();
e.preventDefault();
return false;
});