douqihou7537 2017-02-13 07:09
浏览 28

用户名和密码通过ajax登录..无法登录

Controller code below as show unable to login. none of the error getting what is the problem i cannot understand how to call through ajax

        public function loginn()
            {
                $email=$this->input->post('email');
                $password=$this->input->post('password');

                //$this->load->library('form_validation');

                $this->form_validation->set_rules('email', 'Email or number', 'required|min_length[10]|max_length[30]');
                $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[4]|max_length[40]');

                if ($this->form_validation->run() && $this->Login_model->login($email, $password)) { 
                    $this->welcome();
                } 
                else {
                    $this->form_validation->set_message('check_database', 'Invalid username or password');

                    $this->index(); 

                       }
            }

Below code as shown View page send the post values through ajax.script as below.how to pass the post values to controller using ajax.

  <script type="text/javascript">
$(document).ready(function(){
    $("#fpassf").click(function(){
        //e.preventDefault();
        var email = $("#email").val();
        var password= $("#password").val();


        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>"+"Index.php/Login_cntrl/loginn",
            data: {email:email,password:password},
            success:function(data)
            {
                alert('Successfully login');
            },
            error:function()
            {
                alert('fail');
            }
        });
    });
});


the image shown in below enter image description here

on click on signin image shown in below enter image description here

  • 写回答

2条回答 默认 最新

  • doushan1157 2017-02-13 07:26
    关注

    It seems that you are using Codeigniter Framework. And Hence I have a doubt with your Ajax URL Path.

    You have given

     url: "<?php echo base_url() ?>"+"Index.php/Login_cntrl/loginn",
    

    But In codeigniter it should be like

     url: "<?php echo base_url() ?>"+"/Login_cntrl/loginn",
    

    OR

     url: "<?php echo base_url('Login_cntrl/loginn') ?>",
    

    It can also possible that you are calling this ajax from a script file. Which is not a php file. so the base_url() function will not work there. In that case you have to save base_url into a input variable in a hidden format. and then should be fetch in your ajax code.

    <input type="hidden" name="myurl" value="<?php echo base_url();">
    

    and then ajax one

    var myurl = $("#myurl").val();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃