1

我想set_flasdata在使用 AJAX 提交时显示,但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没有出现的问题,请帮忙。

4

0 回答 0