我试图在附加字段中进行自动填充。 我的codeigniter视图文件:
<div class="right_col" role="main">
<div class="clearfix"></div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<span class="section">Search Product's Info</span>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Product Name <span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="prosearch" class="form-control col-md-7 col-xs-12" name="prosearch" type="text" placeholder="Search">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
我的剧本:
<script type="text/javascript">
var $ = jQuery.noConflict();
$(function() {
// alert('hello');
$( "#prosearch" ).autocomplete({
source: function( request, response ) {
var t = $('#prosearch').val();
$.ajax({
type: "POST",
url: "<?php echo site_url('sale/search') ?>",
data: { term: request.term },
dataType: 'json',
success: function( data ) {
response( $.map( data, function( item ) {
return {
label: item.data,
value: item.product_name,
id: item.id
}
}));
}
});
}
})
});
</script>
我的控制器方法:
public function search(){
$q=$_POST["term"];
#print_r($q); exit;
$query = $this->db->query("SELECT * FROM product WHERE product_name LIKE '".strtoupper($q)."%';");
$data= $query->result_array();
$json = json_encode($data);
echo $json;
}
我正在尝试将我的搜索结果与任何其他自动提示一样在自己的输入下。 任何形式的帮助。