Codeigniter: Simple ajax submit not working

Posted by Kevin Brown on Stack Overflow See other posts from Stack Overflow or by Kevin Brown
Published on 2010-05-07T20:33:32Z Indexed on 2010/05/07 20:38 UTC
Read the original article Hit count: 262

Filed under:
|
|

jQuery:

$('#welcome-message').submit(function() { 
    // inside event callbacks 'this' is the DOM element so we first 
    // wrap it in a jQuery object and then invoke ajaxSubmit 
    $(this).ajaxSubmit({}); 
    $(this).fadeTo(400, 0, function () { // Links with the class "close" will close parent
    $(this).slideUp(400);
    });
    return false; 
}); 

Controller:

function welcome_message() { if(isset($_POST['welcome_message'])) { $this->_my_private_function(); } }

private function _my_private_function()
{

    $id = $this->session->userdata('id');
    $profile['welcome_message'] = '0';
    $this->db->update('be_user_profiles',$profile, array('user_id' => $id));        
    redirect('home', 'location');
}

html:

            <?php print form_open('home/welcome_message',array('class'=>'horizontal','id'=>'welcome-message'))?>
            <p>
                Before you can complete the assessment, you need to complete your profile.  Once that's done you'll be ready!  After you have completed the assessment, you will be able to view the results from your profile.
            </p>
                    <input type="checkbox" value="0" name="welcome_message" checked="false">
                        Don't show me this again
                    </input>                    <p>
                    <input class="button submit" type="submit" class="close-box" value="Close" />
                </p>

            <?php print form_close()?>

This should be working. My hypothesis is that the data isn't being passed to the function...but I really have no idea! It works when I visit the function in the url.

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about AJAX