您好我想知道如何为我点击的每个按钮显示不同的图库。这是我的观看代码:
<div id="gallery-buttons">
<div class="row">
<div class="col-md-2 col-md-offset-3">
<p>Eagle Fruit South Africa</p>
<img src="<?= base_url() ?>assets/img/site/apple.png" class="img-responsive" id="apple"
alt="apple"/>
<button type="button" onclick="saBtn()" class="btn btn-primary btn-sm" id="saBtn">View Gallery
</button>
</div>
<div class="col-md-2">
<p>Eagle Fruit Kenya</p>
<img src="<?= base_url() ?>assets/img/site/avo.png" class="img-responsive" id="strawberry"
alt="avocado"/>
<button type="button" onclick="kenyaBtn()" class="btn btn-primary btn-sm" id="kenyaBtn">View
Gallery
</button>
</div>
<div class="col-md-2">
<p>Eagle Fruit Egypt</p>
<img src="<?= base_url() ?>assets/img/site/strawberry.png" id="eorange" class="img-responsive"
alt="strawberry"/>
<button type="button" onclick="egyptBtn()" class="btn btn-primary btn-sm" id="egyptBtn">View
Gallery
</button>
</div>
</div>
</div>
</div>
所以,当我点击说saBtn时,我希望从该数据库中获取图像并显示在模态中我将如何用ajax实现这一目标
到目前为止,这是我的javascript函数
/* Gallery Modals */
function saBtn(){
$('#modalGallery').modal('show');
$('.modal-title').text('Eagle Fruit South Africa Gallery'); // Set Title to Bootstrap modal title
}
function kenyaBtn(){
$('#modalGallery').modal('show');
$('.modal-title').text('Eagle Fruit Kenya Gallery'); // Set Title to Bootstrap modal title
}
function egyptBtn(){
$('#modalGallery').modal('show');
$('.modal-title').text('Eagle Fruit Egypt Gallery'); // Set Title to Bootstrap modal title
}
我的模型中有以下设置:
function get_sa(){
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('gallery_images', 'gallery_images.gallery_id = gallery.name','left');
$this->db->where('gallery.gallery_name' == 'South Africa');
$query = $this->db->get();
return $query->result('array');
}
function get_egypt(){
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('gallery_images', 'gallery_images.gallery_id = gallery.name','left');
$this->db->where('gallery.gallery_name' == 'Egypt');
$query = $this->db->get();
return $query->result('array');
}
function get_kenya(){
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('gallery_images', 'gallery_images.gallery_id = gallery.name','left');
$this->db->where('gallery.gallery_name' == 'Kenya');
$query = $this->db->get();
return $query->result('array');
}
那么现在如何将结果传递给模态并构建库?
答案 0 :(得分:0)
使用AJAX从codeigniter
获取结果