I have a problem when sending data with ajax,in the URL it adds .php to my controller
need help :(
this is the AJAX script to make call to Welcome controller:
<script>
$(document).ready(function () {
$('#palier').change(function(){
var idf=$(this).val();
console.log(idf);
$.ajax({
url : "<?php echo base_url(); ?>"+"Welcome/affectation_exam",
type : "POST",
data:{idf:idf},
datatype:"text",
success:function(data){
$('#specialite').html(data);
// console.log(data);
}
});
});
})
</script>
in the controller i have :
public function affectation_exam($page='affectation des examens')
{
$data['title']=$page;
$this->load->model('Palier');
$this->load->model('Specialite');
$data['records']=$this->Specialite->get_specialite();
$data['palier']=$this->Palier->get_palier();
$this->load->view('template/main',$data);
echo $_POST["idf"];
}
Try this
$.ajax({
url : "<?php echo base_url(); ?>/welcome/affectation_exam";
...
});
If you have not removed index.php
then use it as
$.ajax({
url : "<?php echo base_url(); ?>/index.php/welcome/affectation_exam";
...
});
Edited
Change your controller code like
public function affectation_exam($page='affectation des examens')
{
$data['title']=$page;
$this->load->model('Palier');
$this->load->model('Specialite');
$data['records']=$this->Specialite->get_specialite();
$data['palier']=$this->Palier->get_palier();
$result = $this->load->view('template/main',$data, TRUE);
//$_POST["idf"];
echo $result; exit;
}
1) There is no requirement for concatenation of URL string.
2) The controller name needs to be in lower-case.
$.ajax({
url : "<?php echo base_url(); ?>welcome/affectation_exam",
.....
});