Skip to content Skip to sidebar Skip to footer

Ajax Function Not Going To Php Codeigniter Controller

I have a ajax function written which is posting different numbers. Here is the ajax function. self.giveCashtoChild = function(){ $.ajax({ type: 'POST',

Solution 1:

You define ajax as POST but you sending it via GET

type: 'POST',
 url: BASEURL + '/index.php/main/addUserChildrenCash'+"/"+self.selectedchild(),

So your code should be

In Ajax

var id = self.selectedchild(); # Assign data to here
$.ajax(
    {

        type:"post",
        url: "<?php echo base_url(); ?>index.php/main/addUserChildrenCash", 
        data:{ id:id},
        success:function()
        {

        }
        error:function()
        {

        }
        always:function(){

        }
    });

In controller

publicfunctionaddUserChildrenCash()
{
    $id = $this->input->post("id");
    echo$id
}

Solution 2:

self.giveCashtoChild = function(){
            var id = self.selectedchild();
            $.ajax({
                type: 'POST',
                url: BASEURL + '/index.php/main/addUserChildrenCash/"+id,
                contentType: 'application/json; charset=utf-8'
            })
            .done(function() {

            })
            .fail(function(xhr, status, error) {
                alert(status);
            })
            .always(function(data){                 
            });
        }

Solution 3:

In your codeigniter use case I would pass your ajax parameter like this:

 $.ajax({
   type: 'post',
   url: BASEURL +'/index.php/main/addUserChildrenCash',
   data: { 'childID': self.selectedchild() },
   })
  ...

In the codeigniter controller I would receive the parameter like this:

publicfunctionaddUserChildrenCash() {
    $childID = $this->input->post("childID");
    ...
    }

You should also check wether your BASEURL has the correct value assigned. Hope this helps.

Post a Comment for "Ajax Function Not Going To Php Codeigniter Controller"