Created
January 23, 2013 17:56
-
-
Save fdb713/4611033 to your computer and use it in GitHub Desktop.
codeigniter check username when logging in using ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ajax_lookUpUsername(){ | |
$username = $this->input->post('username'); | |
$this->db->where('username', $username); | |
$query = $this->db->get('accounts'); | |
if ($query->num_rows() > 0){ | |
echo 0; | |
} else { | |
echo 1; | |
} | |
} | |
?> | |
<script> | |
//and here's your simple onclick javascript function: | |
function lookUpUsername(name){ | |
$.post( | |
'http://yourwebsite/controller/ajax_lookUpUsername', | |
{ username: name }, | |
function(response) { | |
if (response == 1) { | |
alert('username available'); | |
} else { | |
alert('username taken'); | |
} | |
} | |
); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment