You passed username
from jQuery with username: $('#userId').val()
not userId
Try following with $this->input->post('username')
$username = strtolower(trim($this->input->post('username')));
Or change posted data index from jQuery: username
to userId
userId: $('#userId').val()
0
solved Check Username or Password Availability Using AJAX on Codeigniter