Using the remote function of jquery validation

后端 未结 8 693
逝去的感伤
逝去的感伤 2020-12-16 03:12

I\'m trying to figure out how I can turn this:

$(\'#username\').blur(function(){
    $.post(\'register/isUsernameAvailable\', 
           {\"username\":$(\'#         


        
8条回答
  •  忘掉有多难
    2020-12-16 03:39

    I think I am too late to reply. but our code is very easy for all

    Validation Code

    rules: {
                session: {
                   required: true,
                    remote: {
                        url: "",
                        type: "post",
                        data: {
                          session: function() {
                            return $( "#sessionInput" ).val();
                          }
                        }
                      }
                },
            },
    

    Controller Code

    public function checkSession()
        {
            $response = array();
            $session = $this->input->post('session');
    
            $check = $this->dm->checkData('session','session',array('session'=>$session));
    
            if($check)
            {
                echo(json_encode("Session Already Exist")); 
            }
            else
            {
                echo(json_encode(true)); 
            }
        }
    

    Model Code

    public function checkData($data,$tablename,$where)
        {
            $query = $this->db->select($data)
                     ->from($tablename)
                     ->where($where)
                     ->get();
            if($query->num_rows() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    

提交回复
热议问题