Welcome Guest, Not a member yet? Register   Sign In
using jquery ajax with codeigniter
#1

[eluser]fatfishy[/eluser]
Hey I'm new to Codeigniter and I'm wondering why I'm having problems to combine codeigniter with jquery ajax form posts ..

this my form
test.php (views/test.php)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
[removed][removed]

  [removed]
$(document).ready(function() {



  $('#username').blur(function() {

    var username = $("#username").val();
var dataString = 'username=' + username;
  
  alert(username);
  
$.ajax({
  type: "POST",
  url: "/index.php/ajax/username_taken",
  data: dataString,
  success: function(msg)
        {
   $("#status").html(msg);
  }
  });
  });  

});
  
  &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;form action="" method="post"&gt;
username: &lt;input type="text" id="username" /&gt; &lt;br /&gt;
&lt;/form&gt;
&lt;div id="status"&gt;&lt;/div&gt;




&lt;/body&gt;
&lt;/html&gt;
yeah I know I can user form helper, I'm just playing with it ...

and this is controller (controllers/ajax.php)
Code:
&lt;?php

class Ajax extends CI_Controller {



  public function username_taken()
  {
    $this->load->model('Login');
    $username = trim($_POST['username']);
    if ($this->Login->login_check($username))
      echo "exists";
   else
echo "not exists";
  }

}

/* End of file ajax.php */
/* Location: ./system/application/controllers/ajax.php */
?&gt;

and this is the model, login.php (models/login.php)
Code:
&lt;?php
class Login extends CI_Model {


function login_check($username)
{
  $this -> db -> select('id, username');
  $this -> db -> from('users');
  $this -> db -> where('username = ' . "'" . $username . "'");
  $this -> db -> limit(1);

  $query = $this -> db -> get();

  if($query -> num_rows() >= 1)
  {
   return true;
  } else
   return false;
}
}

?&gt;


now, I do getting the alerts with the username I've putted in, but I don't get the result from the server side (exists / not exists) ... I wonder why, what I'm doing wrong.

thanks a lot for the help Smile


Messages In This Thread
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:35 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:51 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:53 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:57 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:57 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 06:59 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:01 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:12 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:13 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:14 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:17 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:20 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:25 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:30 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:32 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:35 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:42 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 07:57 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 08:13 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 08:46 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 08:59 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 09:13 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 09:39 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 10:58 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 11:15 AM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 01:26 PM
using jquery ajax with codeigniter - by El Forum - 11-15-2012, 02:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB