doudouchan5830 2014-08-24 03:25
浏览 58
已采纳

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 2014-08-24 03:34
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作