1

I am working with codeigniter base application. Here I have write ajax function and pass data to my conttoller. Then it gives an error.

My ajax code is like :

$.ajax({
  type:"post",      
  url:"<?php echo base_url(); ?>login/insert_fb",
  data:{record:record,id:id},
  success:function(record_Data){
    alert(record_Data);
  }
});

Here, record variable pass json data.When I print that record in my controller like :

function insert_fb()
{       
    $data = json_decode($this->input->post($record),true);
    print_r($data);
}

then it gives an error like

Undefined variable : record and json_decode() expects parameter 1 to be string,array given.

So, how can I resolve this problem?

1 Answer 1

3

$recore is undefined in your code

$data = json_decode($this->input->post($record),true);

Instead use

$data = json_decode($this->input->post('record'),true);

Because you are sending record in post data using ajax

I think no need of json_decode to get post data using ajax just use

$resore=$this->input->post('record');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.