[eluser]timpiele[/eluser]
I have a select (dropdown) box called #select_make. I use jQuery's .change() function to detect when a user changes it, so I can take an action. I know the .change() function is firing because if I add alert(make); inside of .change() it works.
I just can't seem to get any response from my $.post request though, here's my code, am I doing it wrong? Right now I'd be happy to just return my string "Testing, One, Two, Three, Four" and alert it..
Code:
// jQuery from /views/test_view.php
$(document).ready(function() {
$("#select_make").change(function() {
var make = $('#select_make').val();
$.post('/index.php/test_controller/getdata', { 'make':make }, function(result) {
if (result) {
alert(result);
}
});
});
});
Code:
// test_controller.php
<?php
class Test_Controller extends CI_Controller {
function __construct() {
parent::__construct();
// load required helpers
$this->load->helper('asset');
}
// index function loads the initial view
public function index() {
// load jquery
$data['js'] = js_asset('jquery-1.7.1.min.js');
// load the view
$this->load->view('test_view', $data);
}
// get data function echos a string (for now)
public function getdata() {
// echo a string just to test for a response
echo "Testing, One, Two, Three, Four";
}
}
?>