title: Retrieving data from a form (Codeigniter, AJAX)
body: <p>I have a problem with a form.
  I need to do a login form, but I can't retrieve login data.</p>
  
  <p>This is my view login.php:</p>
  
  <pre><code> &lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
   ?&gt;
   &lt;div class="main"&gt;
     &lt;div class="container"&gt;
        &lt;div class="card card-container"&gt;            
          &lt;h1&gt;Control de Asistencia&lt;/h1&gt;
          &lt;form id="login" class="form-signin" method="post" action="&lt;?php echo 
  base_url('login/ingresar'); ?&gt;"&gt;
              &lt;span id="reauth-email" class="reauth-email"&gt;&lt;/span&gt;
              &lt;input type="email" name="email" id="inputEmail" class="form-control" 
  placeholder="Usuario" required autofocus&gt;
              &lt;input type="password" name="password" id="inputPassword" class="form-control" 
  placeholder="Clave" required&gt;   
              &lt;br/&gt;
              &lt;button class="center btn btn-raised btn-info btn-lg" type="submit"&gt;Ingresar&lt;/button&gt;
              &lt;div class="login__rpta"&gt;&lt;/div&gt;
          &lt;/form&gt;&lt;!-- /form --&gt;            
      &lt;/div&gt;&lt;!-- /card-container --&gt;
    &lt;/div&gt;&lt;!-- /container --&gt;
  &lt;/div&gt;&lt;!--main--&gt;
  </code></pre>
  
  <p>The controller Login.php:</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Login extends CI_Controller {
  
    public function __construct(){
      parent::__construct();
      $this-&gt;load-&gt;model('Login_model');
  }
  
  function ingresar(){
  
      $email = $this-&gt;input-&gt;post("email");
      $password= md5($this-&gt;input-&gt;post("password"));
      $resp = $this-&gt;Login_model-&gt;login($email, $password);
      if($resp){
          $data = [
              "id" =&gt; $resp-&gt;id,
              "name" =&gt; $resp-&gt;nombre,
              "nivel" =&gt; $resp-&gt;nivel,
              "login" =&gt; TRUE
          ];
  
          $this-&gt;session-&gt;set_userdata($data);
      }
      else{
          echo "errorxxx";
      }
    }
  
     function cerrar(){
       $this-&gt;session-&gt;sess_destroy();
       redirect(site_url());
    }
  }
  </code></pre>
  
  <p>Javascript custom.js:</p>
  
  <pre><code>$(function () {
   $.material.init();    
  
   $("#login").submit(function(event){
      event.preventDefault();
      $.ajax({
          url:$(this).attr("action"),
          type:$(this).attr("method"),
          data:$(this).serialize(),
          success:function(resp){
              if(resp==="error"){
                  $('.login__rpta').html("Usuario o clave incorrectos");
                  console.log(resp);
              }
              else{
                  window.location.href = base_url + "welcome/home";
                  console.log(resp);
              }
          }
      });
  });
  ------ more code ------
  });
  </code></pre>
  
  <p>EDITED: this is the model Login_model.php</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Login_model extends CI_Model {
  
  function login($email, $password){
  
      $this-&gt;load-&gt;database();
      $this-&gt;load-&gt;dbutil();
  
      // check connection details
      if( !$this-&gt;dbutil-&gt;database_exists('myDatabase')) {
          echo 'Not connected to a database, or database not exists';
          } else {
          echo 'Conectado';
      }
  
      $this-&gt;db-&gt;where("email", $email);
      $this-&gt;db-&gt;where("password", $password);
      $resultados = $this-&gt;db-&gt;get("profesores");
      if ($resultados-&gt;num_rows()&gt;0) {
          return $resultados-&gt;row();
      }
      else{
          return false;
      }
    }
  }
  </code></pre>
  
  <p>The console.log from custom.js show me the view (the form) instead of the login parameters, and it redirects me to a 404 error page... What am I doing wrong, please?
  This is not my code (I'm just trying to fix it) and I can't see the problem!</p>