doudouchan5830
doudouchan5830
2014-08-24 03:25

jquery ajax表单验证不使用GET方法codeigniter

I have a form where I am checking the username is unique using the jquery ajax. It's working fine but the problem is when I use the GET method , it's returning me the same value again and again . The else statement is not running. It's working absolutely fine with POST method.

Here is the form with my jquery ajax implemented

<script type="text/javascript" src="<?php echo base_url('javascript/script.js');?>"></script>
<script>
$(document).ready(function(){

$("#username").change(function(e){

    $.ajax({
    url:'http://localhost/rental/index.php/members/ajaxVerify',
    type:'POST',
    data:{name:$(this).val()},
    success:function(data){

    $("#error_msg").html(data);
    $("#username").val('');

    }

    //ok will do that verify chaina bhane submit button unclickable banaidimla ...text delete garnu ko sato ....
    }); 

    });
});
</script>
<form method="post" action="<?php echo site_url('members/signupAdd');?>">
<table>
<tr><td>username:</td><td><input type="text" name="username" id="username"></td><td id="error_msg"></td></tr>
<tr><td>email:</td><td><input type="text" name="email" id="email"></td></tr>

<tr><td><input type="submit" name="submit" value="signup"></td></tr>
</table>

</form>

..Here is the model...

function uniqueName($typedname){
        $this->db->where('username',$typedname);
        $query=$this->db->get('users');
        if($query->num_rows>0)
        {
            return true;
        }
        else{
            return false;
        }
    }

And this is the controller..

function ajaxVerify(){
        $typedname=$this->input->post('name');

        //call model to verify unique username
        if($this->members_model->uniqueName($typedname))
        {
            echo "Username already exist";

        }
        else{
            echo '';    
        }   
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doutangliang7769 doutangliang7769 7年前

    If you use type:'GET' in ajax then you should use in ajaxVerify() like this

    $this->input->get('name');
    

    And if you use type:'POST' then

    $this->input->post('name');
    
    点赞 评论 复制链接分享