I have a ajax function written which is posting different numbers. Here is the ajax function.
self.giveCashtoChild = function(){
$.ajax({
type: 'POST',
url: BASEURL + '/index.php/main/addUserChildrenCash'+"/"+self.selectedchild(),
contentType: 'application/json; charset=utf-8'
})
.done(function() {
})
.fail(function(xhr, status, error) {
alert(status);
})
.always(function(data){
});
}
self.selectedchild() has the value of 2 , so Basically the url is addUserChildrenCash/2 but then it does not go to the codeigniter controller and change the page. Here is the controller function.
public function addUserChildrenCash($childID){
if (!$this->session->userdata('user_id')){
redirect('main'); // the user is not logged in, redirect them!
}
$userid= $this->session->userdata('user_id');
$this->load->model('main_page');
$childname = $this->main_page->getChildName($childID, $userid);
$data = array(
'name' => $childname['children_name']
);
$this->load->view('header2_view');
$this->load->view('add_user_children_cash_view' , $data);
$this->load->view('footer_view');
}
In your codeigniter use case I would pass your ajax parameter like this:
In the codeigniter controller I would receive the parameter like this:
You should also check wether your BASEURL has the correct value assigned. Hope this helps.
You define ajax as
POST
but you sending it viaGET
So your code should be
In Ajax
In controller