Skip to content

Instantly share code, notes, and snippets.

@fdb713
Created January 23, 2013 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdb713/4611033 to your computer and use it in GitHub Desktop.
Save fdb713/4611033 to your computer and use it in GitHub Desktop.
codeigniter check username when logging in using ajax
<?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