0
codeigniter에서 ajax를 통해 검색 기능을 사용하고 있습니다 ... 코드가 올바르게 작동하고 있습니다 ... 필요한 일치 항목을 올바르게 검색하지만 내 코드의 문제점은보기에 2 가지를 표시하고 있다는 것입니다. 1. 기본값에 의해 2.searched values 하지만 난 그때에만 기본 값이 아닌 검색 값을 검색 할 때 한 번 표시 기본값입니다. 내 컨트롤러는 다음과 같습니다아약스를 통해 검색을 사용하여 데이터 표시
는public function seller()
{
$this->load->model('home/Home_model');
$ser = $this->input->post('search_data');
if(isset($search))
{
$data['h'] = $this->Home_model->search_seller($search);
}
else
{
$data['h'] = $this->Home_model->seller();
}
$this->load->view('admin/pages/sellers', $data);
}
내 모델은
public function seller()
{
$query = $this->db->get('wc_seller');
return $query;
}
public function search_seller($search)
{
$this->db->select('*');
$this->db->like('seller_name', $search);
$this->db->like('email', $search);
$query = $this->db->get('wc_seller');
return $query;
} 보기 내 아약스 스크립트가
<?php $this->load->view('admin/templates/header'); ?>
<div id="page-wrapper">
<div class="graphs">
<h3 class="blank1">All Sellers</h3>
<div class="something">
<input name="search_data" id="search_data" type="text" onkeyup="ajaxSearch();">
<div id="suggestions">
<div id="autoSuggestionsList">
</div>
</div>
</div>
<div class="xs tabls tabls1">
<div class="panel-body1">
<table class="table table-hover table-responsive">
<thead>
<tr>
<th>Id</th>
<th>Registered On</th>
<th>Email</th>
<th>Full Name</th>
<th>Mobile No</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($h->result() as $row)
{
?>
<form action="<?php echo base_url() . "Home/edit_sellers/" . $row->id; ?>" method="POST">
<tr>
<th scope="row"><?php echo $i; ?></th>
<td><?php echo $row->last_modified;?> </td>
<td><?php echo $row->email; ?></td>
<input type="hidden" name="id" value="<?php echo $row-> id; ?>">
<td><input type="text" name="seller_name" value="<?php echo $row->seller_name;?>" placeholder="<?php echo $row->seller_name;?>" class="form-control"></td>
<td><input type="text" name="mobile_no" value="<?php echo $row->mobile_no;?>" placeholder="<?php echo $row->mobile_no;?>" class="form-control"></td>
<td>
<button type="submit" value="Update" class="btn btn-primary btn-sm">Update</button>
<a type="button" class="btn btn-danger btn-sm" href="<?php echo base_url() . "Home/delete_seller/" . $row->id; ?>" onclick="return confirm('Are you sure you want to delete it?')"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
<?php if($row->status == '1'){
$status = 'Deactivate';
}
else{
$status = 'Activate';
}
?>
<button type="button" class="btn btn-success btn-sm" id="<?php echo $row->id; ?>" onclick="savestatus<?php echo $row->id; ?>(<?php echo $row->id; ?>)"><?php echo $status; ?></button>
</td>
</tr>
</form>
<script>
function savestatus<?php echo $row->id; ?>(row_id){
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/activate_seller/'. $row->id; ?>",
data:{},
success:function(data)
{
//$("#"+row_id).html("Deactivate");
$("#"+row_id).text().trim()==="Activate"? $("#"+row_id).text("Deactivate"):$("#"+row_id).text("Activate")
}
});
}
</script>
<?php
$i++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
function ajaxSearch() {
var input_data = $('#search_data').val();
if (input_data.length === 0) {
$('#suggestions').hide();
//$('.tabls1').show();
} else {
var post_data = {
'search_data': input_data,
'<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
};
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/seller/' ?>",
data: post_data,
success: function(data) {
// return success
if (data.length > 0) {
$('#suggestions').show();
//$('.tabls1').hide();
$('#autoSuggestionsList').addClass('auto_list');
$('#autoSuggestionsList').html(data);
}
}
});
}
}
</script>
<?php $this->load->view('admin/templates/footer'); ?>
이 (전체 HTML 코드를보기 id가있는 div #autoSuggestionsList) –
not working !!!! – Pardeep
전체 HTML 코드를 제공 –