First you can define a global variable that can be used as your base url in the jquery code. Place this in the <script>
tag of the page <head>
section
//<![CDATA[
base_url = '<?php echo base_url();?>';
//]]>
Than do the ajax request like this
var data = 'var1=aaa&var2=bbb';
$.ajax({
type: "POST",
url: base_url+"mainController/getData/", //base_url is the variable which you have defined in the head section
data: data,
success: function(response){
alert(response);
}
});
Than in the controller retrieve the post data like this
class MainController extends CI_Controller {
function getData()
{
$var1 = $this->input->post('var1');
$var2 = $this->input->post('var2');
echo $var1;
echo '<br/>';
echo $var2;
}
}