Welcome Guest, Not a member yet? Register   Sign In
how to check email exist with Jquery and ajax?
#1

[eluser]Kency[/eluser]
Hi everybody i try to check email exists with Jquery and codeigniter but i can't do it

my jquery code

Code:
//check email
             $('#email').blur(function(){
                  var email = $('#email').val();
                 if( $(validateEmail(email) )
                 {
                     var email = $('#email').val();
                     getResultEmail(email);
                 }else{
                     alert("invalid email address");
                 }
                 return false;
             })
             function getResultEmail(email){
                 var baseurl = $('.hiddenUrl').val();
                 $('.checkEmail').addClass('preloader');
                 $.ajax({
                     url : baseurl + 'admin/user/checkemail/'+email,
                     cache : false,
                     success : function(response){
                         $('.checkEmail').removeClass('preloader');
                         if(response == 'userOk') $('.checkEmail').removeClass('userNo').addClass('userOk');
                         else $('.checkEmail').removeClass('userOk').addClass('userNo');

                     }
                 })
             }

             function validateEmail(email) {
                 var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                 return regex.test(email);
             }


and my controller

Code:
public function  checkemail($email){
        
        $query = $this->user_model->checkemail($email);
        if($query == 0) echo 'userOk';
        else echo 'userNo';
    }


and my model

Code:
function checkusername($username)
    {
        $this->db->where('username',$username);
        $query = $this->db->get('user')->num_rows();
        return $query;
    }

my view:

Code:
<div class="formRow">
            <label>Email:<span class="req">*</span></label>
            <div class="formRight">
                &lt;?php

                $data = array(
                    "name" => "email",
                    "value" => "",
                    "required" => "" ,
                    "title" => "",
                    "id" => "email"
                );

                echo form_input($data);
                ?&gt;

                <p class="checkEmail"></p>
                &lt;input type="hidden" class="hiddenUrl" value="&lt;?php echo base_url() ?&gt;"&gt;
            </div>
            <div class="clear"></div>
        </div>


and my problem is when i enter email address into text field, it just show preloader and it can't check email exist or not

i know codeigniter prevent @ in uri (because my code will show uri like admin/user/checkemail/[email protected])

but i try to use another way, but it not work too

i change my code to

Code:
$('#email').blur(function(){

                
                     //var email = $('#email').val();
                     getResultEmail();
                
                 return false;
             })
             function getResultEmail(){

                 var baseurl = $('.hiddenUrl').val();
                 $('.checkEmail').addClass('preloader');
                 $.ajax({
                     url : baseurl + 'admin/user/checkemail/',
                     cache : false,
                     success : function(response){

                         $('.checkEmail').removeClass('preloader');
                         if(response == 'userOk') $('.checkEmail').removeClass('userNo').addClass('userOk');
                         else $('.checkEmail').removeClass('userOk').addClass('userNo');

                     }
                 })
             }


my controller

Code:
public function  checkemail(){
        $email = $this->input->post('email');
        $query = $this->user_model->checkemail($email);
        if($query == 0) echo 'userOk';
        else echo 'userNo';
    }


but i got no result and preloading still load @.@

please help me!


Messages In This Thread
how to check email exist with Jquery and ajax? - by El Forum - 05-19-2012, 03:23 AM
how to check email exist with Jquery and ajax? - by El Forum - 05-19-2012, 07:12 AM
how to check email exist with Jquery and ajax? - by El Forum - 05-19-2012, 11:35 AM
how to check email exist with Jquery and ajax? - by El Forum - 05-19-2012, 12:18 PM
how to check email exist with Jquery and ajax? - by El Forum - 05-22-2012, 06:04 AM
how to check email exist with Jquery and ajax? - by El Forum - 05-23-2012, 04:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB