** codeigniter ajax登录问题**

Login issue with ajax and codeigniter, login failed then show error message in script

ajax script dose not show any action

<script>
     $('#login_form').submit(function (e)
        {
            e.preventDefault();
            var uname = $('#uname').val();
            var upassword = $('#upassword').val();
            if (uname == "" || upassword == "")
            {
                $('#error').show().html('All Fields are required');
            } else {
                $('#error').html("").hide();
                $.ajax({
                    type: "POST",
                    url: "<?= base_url(); ?>User_controller/login_autho/",
                    // datatype: 'json',
                    data: {uname: uname, upassword: upassword},
                    success: function (data) {

                        if (data == '1')
                        {
                         window.location.replace("<?php echo base_url(); ?>User_controller/profile");
                        } else {
                            alert('invalid username');
                        }
                    }
                });
                return false;
            }
        });
</script>

This is a codeigniter controller to check login and open profile.php file

public function login_autho() {
    $data = array(
        'uname' => $this->input->post('uname'),
        'upassword' => $this->input->post('upassword')
    );
    $result = $this->login_model->login_user($data);
    if ($result == TRUE) {
        //adding data to session 
        $this->load->view('header');
        $this->load->view('user_profile');

    } else if($result==FALSE){
        $this->load->view('user/header');
        $this->load->view('user/login');
   }
}
查看全部
weixin_33695450
weixin_33695450
2016/05/27 06:36
  • codeigniter
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

3个回复