1

Since I am very new to ajax I couldn't figure out a way to do it. First let me show my code. I am working on CodeIgniter. The page has got a Google pie chart and when I click on a slice of pie chart I wanted to display the details regarding that value of slice from the database.

For that I used ajax, and do not know how to proceed.

Here's my code:

View: (the part where ajax lines are written)

    function selectHandler() {
      var selectedItem = chart.getSelection()[0];

      if (selectedItem) {
        var topping = data.getValue(selectedItem.row, 0);

       $.post("http://localhost/offlearn/index.php/ctrl_offapp/trail2",
    {
      top: topping,

    },
    function(res,status){
       //alert(res);
        document.getElementById('tablePrint').innerHTML = res; **//Here i //simply tried to print the value to check and its working**
    });

Select handlerfunction was to work when i click on a slice of pie chart.

Controller function:

    public function trail2()
   {
     $var=$this->input->post('top');
     echo $var;
   }

What i want is,i want to use the variable 'res' in ajax callback in a php code in the same view page . The php code i intend to write is :

    <table><tr><td >TASK NAME</td><td >ASSIGNED TO</td><td >CREATED BY</td></tr>
     <?php foreach($ts->result() as $tk)
     {  
     if ($tk->status ==  **res** ) //***Here i want to use res***
     {         ?> 
     <tr><td ><?php echo $tk->taskname ?></td><td > 
     <?php foreach($u->result() as $usr)
     { if ($usr->id ==  $tk->assignto) {
     echo  $usr->fname?> </td><td >
    <?php  }}
    foreach($u->result() as $usr)
     { if ($usr->id ==  $tk->createdby ) {
     echo $usr->fname ?></td></tr>
    <?php  }} ?>
     </table>

Any alternate solution is also accepted. And I have very less idea about AJAX so please explain the method like that.

halfer
  • 19,824
  • 17
  • 99
  • 186
AnnaMary
  • 23
  • 5

0 Answers0