0

I have three view files in views folder and i want to show category table and product table by click in link button using ajax call... input.php display both table data

<div class="wrapper">
    <div class="container">
        <div class="jumbotron">
         <h1>View Two Records By Click Event</h1>
        </div>

    <div id="show-catg">  
        <?php $this->load->view('show'); ?> 
    </div>  

    <div id="show-prd">  
         <?php $this->load->view('show_pro'); ?> 
    </div> 

but i want to show this using click event.. like

<a href="" class="show_catg">Categories</a> 
<a href="" class="show_prd">Product</a>
$('.show_catg').click(function(){
  url:,
  data:,
});
$('.show_prd').click(function(){
  url:
  data:
});

this is may controller class function

  public function index(){  
    $data= $this->Model_data->getAll_categories();  
    $data1 = $this->Model_data->getAll_product();
    $Dataa = array('categories' => $data,"products"=>$data1);
    $this->load->view('input',$Dataa); 

  }

Model_data class

  function getAll_categories(){  
    $this->db->select('*');  
    $this->db->from('categories');  
    $this->db->limit(50);  
    $this->db->order_by('Catg_ID','ASC');  
    $query = $this->db->get();  

    return $query->result();  
  }  
public function getAll_product(){  
    $this->db->select('*');  
    $this->db->from('product');  
    $this->db->limit(50);  
    $this->db->order_by('Prod_ID','ASC');  
    $query = $this->db->get();  

    return $query->result();  
  } 
1
  • okay.. but really need help.... :| Commented Nov 8, 2015 at 7:33

1 Answer 1

1

First call getAll_categories() in a different method. like

In Xyz.php file (controller)

public function get_cat(){  
  $data = $this->Model_data->getAll_categories(); 
  $html  = ''; 
  foreach($data as $d){
    $html .= '<li>'.$d['cat_name'].'</li>';
  } 
 echo $html;
 }

jquery code

$('.show_catg').click(function(){
  url: site_url('xyz/get_cat'),
  type:'post',
  dataType: 'html',
  success: function (response) {
      $('#suggestion').show().html(response);
   },
});

do in similar manner for getAll_product() method

Sign up to request clarification or add additional context in comments.

1 Comment

sir i didn't get how to call may view data through ajax and yes i already did that.... as i mentioned i created 3 view files in which 1 file fetch the record from the database but the thing is i'm not getting how can i call my view category file through ajax which is in a seperate file.... this is my category view <?php foreach ($categories as $row){ echo "<tr class=\"record\">"; echo "<td>$row->Catg_ID</td>"; echo "<td>$row->Catg_Name</td>"; echo "</tr>"; } ?>

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.