views:

54

answers:

1

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);
});
+2  A: 

You have to echo the variable:

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

See also CodeIgniter's View User Guide.

Felix Kling