duankuaizhe8257 2015-11-08 07:11
浏览 38

在Codeigniter中使用AJAX调用加载表

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条回答 默认 最新

  • douou9786 2015-11-08 08:58
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错