使用AJAX时set_flashdata codeigniter无法正常工作

时间:2012-12-26 13:30:38

标签: php jquery codeigniter

我想在使用AJAX提交时显示set_flasdata,但set_flashdata没有出现。

这是我的控制器:

public function updatePassword() {
    $idUser = $this->session->userdata('id_user');
    $username = $this->session->userdata('username');
    $data = array();
    $data = $this->user_model->getPassword($idUser, $username);

    $passwordLama = $this->input->post('password-lama');
    $passwordBaru = $this->input->post('password-baru');
    if ($passwordLama == $data['password']) {
        $dataPasswordBaru = array(
            'password' => $passwordBaru
        );
        $this->user_model->updatePassword($idUser, $username, $dataPasswordBaru);
        echo $this->session->set_flashdata('flashSuccess', 'Berhasil mengubah password');
    } else {
        echo $this->session->set_flashdata('flashError', 'Gagal mengubah password');
    }
}

我的观点:

        <?php if ($this->session->flashdata('flashSuccess')): ?>
            <div class="alert alert-success info-alert" id="result-edit-password2">
                <button type="button" class="close" id="close-edit-password2">&times;</button>
                <div id="result-edit-password-text2"><?php echo $this->session->flashdata('flashSuccess') ?></div>
            </div>
        <?php endif ?>

        <?php if ($this->session->flashdata('flashError')): ?>
            <div class="alert alert-error info-alert" id="result-edit-password2">
                <button type="button" class="close" id="close-edit-password2">&times;</button>
                <div id="result-edit-password-text2"><?php echo $this->session->flashdata('flashError') ?></div>
            </div>
        <?php endif ?>

这是我的AJAX:

    $("#form-edit-password").submit(function(e){
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url('home/updatepassword'); ?>",                        
            data: $(this).serialize(),               
            success: function(html){
                $('.info-alert').show();                    
            }
        });
    });

是否存在set_flashdata未出现的问题,请提供帮助。

0 个答案:

没有答案