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 '';
}
}