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

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题