Welcome Guest, Not a member yet? Register   Sign In
ajax check members available not work
#11

[eluser]Why Me[/eluser]
[quote author="noideawhattotypehere" date="1380615743"]Update your files on the server and i will take a look whats wrong.[/quote]

i update a files

code contr

Code:
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

[eluser]noideawhattotypehere[/eluser]
First of all get real man, stop using jquery 1.2.6... Lets go then.
Code:
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
&lt;/script>

then change your function to:
Code:
$(document).ready(function(){

$("#username").change(function() {

var usr = $("#username").val();

if(usr.length >= 4)
{
$("#status").html('<img src="http://www.d4yd.com/mycode/images/loader.gif" align="absmiddle">&nbsp;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('&nbsp;<img src="http://www.d4yd.com/mycode/images/tick.gif" align="absmiddle">');
}  
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

[eluser]Why Me[/eluser]
[quote author="noideawhattotypehere" date="1380621374"]First of all get real man, stop using jquery 1.2.6... Lets go then.
Code:
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
&lt;/script>

then change your function to:
Code:
$(document).ready(function(){

$("#username").change(function() {

var usr = $("#username").val();

if(usr.length >= 4)
{
$("#status").html('<img src="http://www.d4yd.com/mycode/images/loader.gif" align="absmiddle">&nbsp;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('&nbsp;<img src="http://www.d4yd.com/mycode/images/tick.gif" align="absmiddle">');
}  
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()[/quote]

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

#14

[eluser]noideawhattotypehere[/eluser]
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

[eluser]Why Me[/eluser]
[quote author="noideawhattotypehere" date="1380628734"]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).[/quote]

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
#16

[eluser]noideawhattotypehere[/eluser]
My last try
Controller:
Code:
class Your_controller extends CI_Controller {
public function ajax_checklogin() {
        $login = $this->input->post('login', TRUE);
        if (!$this->user_model->if_exists(array('login' => $login))) {
            echo 'Free';
            return FALSE;
        }
        echo 'Taken';
        return FALSE;
    }
}
View:
Code:
$.post("&lt;?php echo base_url()?&gt;your_controller/ajax_checklogin", { login: $("#selector").val() })
                        .done(function(data) {
                    $("#otherselector").html(data);
                });

user_model->ajax_checklogin returns true if exists, false if not.
#17

[eluser]Why Me[/eluser]
hello bro

i try to used get and working good but if change to type post not work

code for type GET
temp => controller
Code:
class Your_controller extends CI_Controller {
    
    public function test_ajax()
    {
        $this->load->view('view_user');
    }
    public function info_page()
    {
         if  ($this->input->get('name', TRUE)){
              echo $this->input->get('name', TRUE);
         }
         else {
             echo "Error";
         }
    }

}

temp = > view

Code:
&lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;Testing Ajax&lt;/title&gt;
      [removed][removed]
      [removed]
            var base_url =  "&lt;?php echo base_url(); ?&gt;" ;
            $(document).ready(function(){
            $('#gebutton').click(function(){
            $.get(base_url+'your_controller/info_page',{name:'My Name.!'},function(data){
            alert(data);
           });
         });
       });
[removed]
   &lt;/head&gt;  
      &lt;body&gt;
              <button  class="sub"id="gebutton">Getname</button>
      &lt;/body&gt;
&lt;/html&gt;
if used type post have error
"NetworkError: 500 Internal Server Error - http://localhost/mycode/your_controller/info_page

you think a problem from config my loclalhost or config codeigniter?
#18

[eluser]noideawhattotypehere[/eluser]
Both post and get works flawlessly on my local enviroment. No idea what might be wrong in yours tho.

Wild guess, swap
{name:'My Name.!'}
to
{ name: "My Name.!" },
Also what response exactly do you get in firebug?
#19

[eluser]Why Me[/eluser]
[quote author="noideawhattotypehere" date="1380702319"]Both post and get works flawlessly on my local enviroment. No idea what might be wrong in yours tho.

Wild guess, swap
{name:'My Name.!'}
to
{ name: "My Name.!" },
Also what response exactly do you get in firebug?[/quote]

error

SyntaxError: illegal character


...t(base_url+'your_controller/info_page',{ name: “My Name.!” },function(data)


#20

[eluser]Why Me[/eluser]
Hello

i Solved


I change $config['csrf_protection'] = TRUE; to $config['csrf_protection'] = FALSE;

everything now fine

thank alot noideawhattotypehere




Theme © iAndrew 2016 - Forum software by © MyBB