ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

ajax check members available not work

September 30, 2013 12:39am

Subscribe [1]
  • #1 / Sep 30, 2013 12:39am

    Why Me

    10 posts

    hello

    i have a problem with code ajax not work

    code model

    public function check_member_available($username)
      {
         $query = $this->db->get_where('members',array('username'=> $username));
          $HTML='';
         if($query->num_rows() == FALSE)
         {
            $HTML='not exists';
         }
         else 
         {
            $HTML='user exists';
         }
         echo $HTML;
      }

    code controllers

    public function check_members()
      {
         $this->load->model('users');
         if($this->input->post('username'))
         {
             $username = $this->input->post('username');
             $this->users->check_member_available($username);
         }
         
         
          
         $this->load->view('cajax');
      }

    code view

    <div id="container">
        <div id="wrapper">
             <div id="form">
                 <label>Choose Your Username</label>
          <input type="text" autocomplete="off" name="user_name" id="user_id" class="user_name" >
                 <span class="check"></span> <br><br> 
             </div>
        </div>
    
    </div>
    
    [removed][removed]
    <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/css/style.css" />
    [removed]
    $(function()
    {
      $('.user_name').keyup(function()
      {
      var checkname=$(this).val();
     var availname=remove_whitespaces(checkname);
      if(availname!=''){
      $('.check').show();
      $('.check').fadeIn(400).html('<?php echo base_url();?>images/image/ajax-loading.gif ');
    
      var String = 'username='+ availname;
      $.ajax({
              type: "POST",
              url: "<?php echo site_url();?>/home/check_members",
              data: String,
              cache: false,
              success: function(result){
                   var result=remove_whitespaces(result);
                   if(result==''){
                           $('.check').html('<?php echo base_url();?>images/image/accept.png This Username Is Avaliable');
                           $(".check").removeClass("red");
                 $('.check').addClass("green");
                           $(".user_name").removeClass("yellow");
                           $(".user_name").addClass("white");
                   }else{
                           $('.check').html('<?php echo base_url();?>images/image/error.png This Username Is Already Taken');
                           $(".check").removeClass("green");
            $('.check').addClass("red")
                           $(".user_name").removeClass("white");
                           $(".user_name").addClass("yellow");
                   }
              }
          });
       }else{
           $('.check').html('');
        
       }
      });
    
    });
    
    function remove_whitespaces(str){
         var str=str.replace(/^\s+|\s+$/,'');
         return str;    
    }
    [removed]

    if check a code without codeigniter work
    but with codeigniter not work
    i hope someone help me

  • #2 / Sep 30, 2013 5:12am

    What your console is saying after you try to use AJAX call from app? Firefox+Firebug is your best friend when developing.

  • #3 / Sep 30, 2013 5:30am

    Why Me

    10 posts

    What your console is saying after you try to use AJAX call from app? Firefox+Firebug is your best friend when developing.

    hello
    ajax code not have any problem i check without codeigniter and working fine,  in codeigniter not work and
    can you check to code please
    and if you have example for how used ajax send me

  • #4 / Sep 30, 2013 5:49am

    I will help you when you do what i asked for.

  • #5 / Sep 30, 2013 6:13am

    Why Me

    10 posts

    I will help you when you do what i asked for.

    can you try => http://d4yd.com/mycode/home/check_members

  • #6 / Sep 30, 2013 7:21am

    change this

    public function check_members()
      {
         $this->load->model('users');
         if($this->input->post('username'))
         {
             $username = $this->input->post('username');
             $this->users->check_member_available($username);
         }
         
         
          
         $this->load->view('cajax');
      }

    to

    public function check_members()
      {      
         $this->load->view('cajax');
      }  
    
    public function ajax_check_members()
    {
         $this->load->model('users');
         if($this->input->post('username'))
         {
             $username = $this->input->post('username');
             $this->users->check_member_available($username);
         }
    }

    and call ajax_check_members via ajax, not check_members, you are loading whole view which gives you internal error.

    PS: Escape your input: $username = $this->input->post(‘username’, TRUE);

  • #7 / Sep 30, 2013 3:26pm

    Why Me

    10 posts

    change this

    public function check_members()
      {
         $this->load->model('users');
         if($this->input->post('username'))
         {
             $username = $this->input->post('username');
             $this->users->check_member_available($username);
         }
         
         
          
         $this->load->view('cajax');
      }

    to

    public function check_members()
      {      
         $this->load->view('cajax');
      }  
    
    public function ajax_check_members()
    {
         $this->load->model('users');
         if($this->input->post('username'))
         {
             $username = $this->input->post('username');
             $this->users->check_member_available($username);
         }
    }

    and call ajax_check_members via ajax, not check_members, you are loading whole view which gives you internal error.

    PS: Escape your input: $username = $this->input->post(‘username’, TRUE);

    hello

    i change everything but not work
    i dont know why
    please help

  • #8 / Oct 01, 2013 3:32am

    This is what happens when you dont listen to my advices. Firefox+firebug would tell you everything what happens between you and server.
    “NetworkError: 404 Not Found - http://d4yd.com/mycode/ajax_check_members”
    URL in your ajax call is wrong, you need to give correct one.

  • #9 / Oct 01, 2013 4:13am

    Why Me

    10 posts

    This is what happens when you dont listen to my advices. Firefox+firebug would tell you everything what happens between you and server.
    “NetworkError: 404 Not Found - http://d4yd.com/mycode/ajax_check_members”
    URL in your ajax call is wrong, you need to give correct one.

    hello noideawhattotypehere

    site not update new files

    im work a localhost and i check Firefox+firebug not have any error and a code not work

    i dont know why all code for ajax not work with codeigniter
    can you help me please im new to ci only used   5 days

     

  • #10 / Oct 01, 2013 4:22am

    Update your files on the server and i will take a look whats wrong.

  • #11 / Oct 01, 2013 5:04am

    Why Me

    10 posts

    Update your files on the server and i will take a look whats wrong.

    i update a files

    code contr

    class Ajax_post extends CI_Controller {
      
      public function getwhere(){
            //$this->load->library('javascript');
            if($this->input->post('username', TRUE)){
            $username = $this->input->post('username', TRUE);
            $query = $this->db->get_where('members',array('username'=>$username));
            if ($query->num_rows() == 1){
               echo '<font color="red">The nickname <strong>'.$username.'</strong> is already in use.</font>';
            }else {
                    echo "OK";
            }
        } 
        
         
     }
      public function check_members(){
        
         $this->load->view('ajax_view');
      }
     
    }
  • #12 / Oct 01, 2013 5:56am

    First of all get real man, stop using jquery 1.2.6… Lets go then.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>

    then change your function to:

    $(document).ready(function(){
    
    $("#username").change(function() { 
    
    var usr = $("#username").val();
    
    if(usr.length >= 4)
    {
    $("#status").html('http://www.d4yd.com/mycode/images/loader.gif Checking availability…');
        $.ajax({  
        type: "POST",  
        url: "http://www.d4yd.com/mycode/ajax_post/getwhere",  
        data: { username: usr }  
      }).done(function(msg){
          if(msg == 'OK')
     { 
            $("#username").removeClass('object_error'); // if necessary
      $("#username").addClass("object_ok");
      $(#status).html(' http://www.d4yd.com/mycode/images/tick.gif');
     }  
     else  
     {  
      $("#username").removeClass('object_ok'); // if necessary
      $("#username").addClass("object_error");
      $(#status).html(msg);
     }  
      }) 
    
    }
    else
     {
     $("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
     $("#username").removeClass('object_ok'); // if necessary
     $("#username").addClass("object_error");
     }
    
    });
    
    });

    Ofc swap hardcoded urls with base_url()

  • #13 / Oct 01, 2013 6:39am

    Why Me

    10 posts

    First of all get real man, stop using jquery 1.2.6… Lets go then.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>

    then change your function to:

    $(document).ready(function(){
    
    $("#username").change(function() { 
    
    var usr = $("#username").val();
    
    if(usr.length >= 4)
    {
    $("#status").html('http://www.d4yd.com/mycode/images/loader.gif Checking availability…');
        $.ajax({  
        type: "POST",  
        url: "http://www.d4yd.com/mycode/ajax_post/getwhere",  
        data: { username: usr }  
      }).done(function(msg){
          if(msg == 'OK')
     { 
            $("#username").removeClass('object_error'); // if necessary
      $("#username").addClass("object_ok");
      $(#status).html(' http://www.d4yd.com/mycode/images/tick.gif');
     }  
     else  
     {  
      $("#username").removeClass('object_ok'); // if necessary
      $("#username").addClass("object_error");
      $(#status).html(msg);
     }  
      }) 
    
    }
    else
     {
     $("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
     $("#username").removeClass('object_ok'); // if necessary
     $("#username").addClass("object_error");
     }
    
    });
    
    });

    Ofc swap hardcoded urls with base_url()

    i change everything and update to server but not work
    if you have any code ajax work send me please

     

  • #14 / Oct 01, 2013 7:58am

    Ok lets clear some things up, you go to http://d4yd.com/mycode/home/check_members
    then your ajax function calls http://www.d4yd.com/mycode/ajax_check_members - do you see your problem? you are missing one uri segment (home).

  • #15 / Oct 01, 2013 3:14pm

    Why Me

    10 posts

    Ok lets clear some things up, you go to http://d4yd.com/mycode/home/check_members
    then your ajax function calls http://www.d4yd.com/mycode/ajax_check_members - do you see your problem? you are missing one uri segment (home).

    i check many code ajax to codeigniter and not have code work
    i hated codeigniter
    can you send me any code work with ci
    any example

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases