I've started my first CodeIgniter project and am having a lot of trouble making an Ajax call to my controller. I've put a simple echo statement in the controller but am getting a console error in the browser - POST http://localhost:8888/lotto/get_results/ 404 (Not Found)
. This leads me to believe that i'm not referencing the controller properly in the AJAX call. Below is the relevant code.
View - index.php
$(document).ready(function(){
$('#notification').hide();
retrieveValues();
});
$('.numDraws').change(function(){
retrieveValues();
});
function retrieveValues() {
if (!checkConnection()) {
$('#notification').html("<span>No internet connection available</span>");
$('#notification').slideDown(500, 'linear');
return;
} else {
$('#notification').slideUp(500, 'linear');
$('#loading').fadeIn(200);
var numOfDraws = parseInt($('.numDraws').find('option:selected').val());
if (isNaN(numOfDraws)) {
numOfDraws = "ALL";
}
$.ajax({
url: "/lotto/get_results/",
type: "post",
data: {numOfDraws:numOfDraws},
success: function (data) {
// var json = $.parseJSON(data);
// setTimeout(function(){displayResults(json)} ,1200);
alert(data);
}
});
}
}
Controller - lotto.php
<?php
class Lotto extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('lotto_model');
}
public function index()
{
$data['title'] = "Home";
$this->load->view('templates/header', $data);
$this->load->view('lotto/index');
$this->load->view('templates/footer');
}
public function get_results($numOfDraws) {
//$data['results'] = $this->lotto_model->get_results(1);
echo "Reached the controller";
}
}
?>
Also in my config file i've got the following:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Any help would be appreciated - i've spent a lot of time on this but can't seem to figure it out.