doutizong8099
2017-11-03 16:34
浏览 61
已采纳

会话闪存数据无法在ajax中运行

there is a change password feature in my admin now before changing password i am validating by asking user to enter the username password again now if the user password is incorrect what i am doing is setting flash data and logging the user out. so when he comes to main login panel he should see the error now here is my code

the controller method

public function checkpassword(){
        $this->check_unique_id_from_db_for_secuity();
        $unique_id=base64_decode($this->uri->segment(3));
        $data = $this->input->post();
        $data['unique_id']=$unique_id;
        $status=$this->User_model->validate_user_loged_in_for_change_password($data);
        if($status){
            echo "true";
            exit();
        }
        else
        {
            $this->session->set_flashdata('change_password_credentials_error',"Your Username/Password was incorect account was logged out for secutiry reasons!");
            echo "false";
            exit();
        }
    }

the ajax request

$.ajax({
            type: 'post',
            url: '<?php echo base_url()."User/checkpassword/".$this->uri->segment(3).""; ?>',
            data:{ "login_username" : $("#login_username").val(), "login_password" : $("#login_password").val() },
            success: function (data) {
                if(data=="true"){
                    window.location.href="<?php echo base_url()."User/changepassword_view/".$this->uri->segment(3)."";?>";
                }
                else
                {
                    window.location.href="<?php echo base_url()."User/logout";?>";
                }
            }

        });

the php script on main login page

<?php
    if($this->session->flashdata('change_password_credentials_error')){?>
        <script>toastr["success"]("<?php echo $this->session->flashdata('change_password_credentials_error')?>");</script>
    <?php } ?>

now the flash data is working just fine i am using it in many other pages but when i am using it with ajax somehow it is not being set! any help?

1条回答 默认 最新

相关推荐 更多相似问题