0

How to pass a php json encoded variable to a jquery function using codeigniter? My code

 $data['customerlist'] = $this->customerlist->customerchart();
   //print_r($data['customerdata']);
   $data['encoded_data'] = json_encode($data);
   //print_r($data['encoded_data']);
    if(empty($data['encoded_data']))
    {
       $data['comment']='No Record Found !';
    }

   $this->load->view('graph', $data);

and in my graph.php; i have this,

$(document).ready(function() {
 PageViews($encoded_data);
});

1 Answer 1

2

You have to echo the variable:

$(document).ready(function() {
   PageViews(<?php echo $encoded_data; ?>);
});

See also CodeIgniter's View User Guide.

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.