Blog

Codeigniter Tutorial: How To check Username/Email availablity using jQuery in Codeigniter?

This post is for CI lover who wants to learn Codeigniter. This script will show you how can we check live availability of username or email using Ajax in Codeigniter. Using this tutorial you can also understand how can we send a jQuery Ajax request to server living in CI.

 

[ad#ad-4]
In your view where you have created form include jQuery library and put the below code there.
In header section:

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$(document).ready(function() {
    /// make loader hidden in start
    $('#Loading').hide();    
 
    $('#email').blur(function(){
    var a = $("#email").val();
    var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
       // check if email is valid
    if(filter.test(a)){
                // show loader
        $('#Loading').show();
        $.post("<!--?php echo base_url()?-->controller_name/check_email_availablity", {
            email: $('#email').val()
        }, function(response){
                        //#emailInfo is a span which will show you message
            $('#Loading').hide();
            setTimeout("finishAjax('Loading', '"+escape(response)+"')", 400);
        });
        return false;
    }
});
function finishAjax(id, response){
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
 
.

Add Comment