Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Remove old result - Ajax

$
0
0
Hi CI Team,

I very need your help to fix this,

1.How to remove old result when I click another category?  
2.How to show all categories without click "All Categories" ?

Please help me....

View:
PHP Code:
<class="nav-link active" onclick="product_category(''); return false;" id="tab-all" data-toggle="tab" href="#tab-all" role="tab">All Categories</a>
<
class="nav-link active" onclick="product_category('1'); return false;" id="tab-1" data-toggle="tab" href="#tab-1" role="tab">Category 1</a>

<
class="nav-link active" onclick="product_category('2'); return false;" id="tab-2" data-toggle="tab" href="#tab-2" role="tab">Category 2</a>

<
class="nav-link active" onclick="product_category('3'); return false;" id="tab-3" data-toggle="tab" href="#tab-3" role="tab">Category 1</a>



<
div class="row justify-content-center" id="category">
</
div>

<
script>
function 
product_category(id){
    $.
ajax({
        
url"<?php echo base_url('main/getValues/');?>"+id,
        
dataType'json',
        
type"POST",
        
cachefalse,
        
success:function(data){
            var 
len data.results.length;
            for (var 
0ileni++) {
                var 
id  data.results[i].id;
                var 
thumbnail  data.results[i].thumbnail;
                $(
"#category").append("<div class='col'><div class=''><img class='' src='"+site_url+'uploads/products/'+id+'/thumb_'thumbnail +"'></div></div>");
            }
        }
    });
}
</script> 


Controller:
PHP Code:
function getValues($id=''){
 
       $data['results'] = $this->products_model->get_product_by_category($id);
 
       $this->output->set_content_type('application/json');
 
       $this->output->set_output(json_encode($data));
 
       return $data;
 
   

Model:
PHP Code:
public function get_product_by_category($id '')
 
   {
 
       $this->db->select('*');
 
       $this->db->where('category'$id);
 
       $products $this->db->get('products')->result();

 
       return $products;
 
   

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>