Ajax Tutorial
- What is Ajax
- How Ajax Work
- ajax() and load() Function
- AJAX get() and post() Methods
- AJAX Function
- Ajax Success
- Ajax Button Click
- Ajax div load on button click
- Insert Data
- Delete Data
- User Registration
- ContactUs Form
- Check existing Password in Ajax and change the Password
- Ajax Search
- Ajax Serialize Insert
- Ajax without Searialize Insert
- Ajax User Check Availability
- Ajax OptionBox
- Ajax Dropdown Session
- dynamic text box Add/Remove
- Star Rating
- Pin Check Available
- Ajax Programs
- Clear Form Field after submitting form
- Loader load show / hide
- Multiple Functions
Customer Say
How to load div content on button click using ajax with db.
File name : controller.php
public function showcomments()
{
//$leader_id = $this->uri->segment(3);
$leader_id = $this->input->get('id');
$commentsresult = $this->Auth_model->getcomments_info($leader_id);
$data['commentsdata'] = $commentsresult;
//load the home view
$comment_html = $this->load->view('comments',$data,true);
echo $comment_html;
exit;
}
View Page
File name : view.php
<html>
<head>
</head>
<script type="text/javascript">
$(function(){
$('.btn').click(function(){
var lid = this.id ;
$.ajax({
type:'GET',
data:'id='+lid,
url : '<?php echo base_url();?>home/showcomments',
success:function(result){
//alert(response);
$("#comment_list").html(result);
},
error: function(msg){
alert("error");
}
});
});
});
</script>
<body>
<a href="javascript:void(0)" class="btn"
id="<?php echo $row->id; ?>">Show Comments</a>
<div id="comment_list">
</div>
</body>
</html>
File name : comments.php
<table class="table datatable">
<thead>
<tr>
<th>Comments By</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<?php
$kk = count ( $commentsdata );
if($kk > 0){
for($c = 0; $c < $kk; ++ $c) {
?>
<tr>
<td><?php echo $commentsdata[$c]->user_name; ?></td>
<td><?php echo $commentsdata[$c]->comments; ?></td>
</tr>
<?php }
}
else {
?>
<tr>
<td>No Comments</td>
</tr>
<?php }?>
</tbody>
</table>
File name : index.php
File name : index.php
File name : index.php