使用ajax和codegniter添加数据

时间:2018-02-04 21:12:43

标签: php ajax codeigniter

iam new in codegniter我尝试使用ajax在表格中添加数据当我发送数据时我现在已经知道并且所有数据都发送良好但没有数据存储在数据库中这是我的代码控制器

public function addusersajax()
{
    if($this->input->post("action") =="addusersintable")


    {
        $this->load->helper('date');
        $data=array(
            "fullname"=> $this->input->post("fullname"),
            "username"=> $this->input->post("username"),
            "password" => md5($this->input->post("password")),
            "email"=>$this->input->post("email"),
            "groubid"=>$this->input->post("groubid"),
            "date"=>mdate('%Y-%m-%d ', now()),
            "time"=>date(" H:i:s")

        );
        $this->load->model("usersmodel");
        if($this->usersmodel->adduserbyajax($data)){
            echo "done";
        }else{
            echo 'failed';
        }



    }

    }

public function view()
{
    $data['pagetitle']="xx";
    $this->load->view("template/admin/header",$data);
    $this->load->view("users/ss",$data);

    $this->load->view("template/admin/footer");

}

我的观看页面

                                                              全名 :                                                                            用户名 :                                                                            密码:                                                                                                 邮箱:                                                                            用户类型 :                                              管理员联络                         用户                         制作者                         cheker                                                                            图片 :                                                   addcc
<script>
    $(document).ready(function () {
        $(function () {
            $("#insercodegn").on('submit', function (e) {

                e.preventDefault();

                $.ajax({

                    url:'<?php echo base_url()?>Users/addusersajax',
                      //url:"<?php echo base_url() .'Users/addusersajax'?>",

                    method:'post',
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData: false,
                    success:function(data)  {
                        alert(data);
                    }


                })



            })

        })

    })

</script>

这是模型代码

public function addusersajaxx($data)
{
    if($this->db->insert("users",$data)){
        return true;
    }else{
        return false;
    }
}

0 个答案:

没有答案