Im having an issue on my CI code. I cant access the authenticate method of my Login controller. There's a 404 error appearing in my browser window.
Here's my code
<!--This will serve as the form -->
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="">Brand</a>
</div>
<form role="form" class="navbar-form navbar-right login-form">
<div class="form-group">
<input type="text" placeholder="Username" class="form-control" name="username">
<input type="password" placeholder="Password" class="form-control" name="password">
</div>
<input type="submit" class="btn-default btn" value="Login" id="btn-login">
</form>
</div><!-- /.container-fluid -->
</nav>
This is the Login Controller with the authenticate() method.
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user');
}
public function index() {
$this->load->view('login');
$this->template->set_layout('default');
$this->template->set_partial('nav', 'partials/nav');
$this->template->append_metadata('<script src="' . base_url("js/script.js") . '"></script>');
$this->template->build('login');
}
public function authenticate() {
$error=0;
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($this->user->login($username, $password)) {
$error=0;
echo json_encode(array('status' => 'success', 'error' => $error));
} else{
$error=1;
echo json_encode(array('status' => 'error', 'error' => $error));
}
echo json_encode(array('status' => 'success', 'error' => $error));
}
}
Im calling the controller using AJAX with the url: "login/authenticate" and the default controller is set to Login. I have no problem with the model. I'm sure that I have configured it properly. Thank You.