0
我已经做了控制自动完成,但我有一个问题,用jQuery发布数据。textbox codeigniter中的自动完成值
<input type="text" id="matakuliah" class="med" name="matakuliah">
<script type="text/javascript">
$(this).ready(function() {
$("#matakuliah").autocomplete({
minLength: 1,
source:
function(req, add){
$.ajax({
url: "<?php echo site_url('bahanAjar/lookup'); ?>",
dataType: 'json',
type: 'POST',
data:req,
success:
function(data){
if(data.response =="true"){
add(data.message);
}
},
});
},
});
});
</script>
我控制器
function lookup(){
// process posted form data (the requested items like province)
$keyword = $this->input->post('term');
$data['response'] = 'false'; //Set default response
$query = $this->matakuliah_model->lookup($keyword); //Search DB
if(! empty($query))
{
$data['response'] = 'true'; //Set response
$data['message'] = array(); //Create array
foreach($query as $row)
{
$data['message'][] = array(
'id_matakuliah'=>$row->id,
'value' => $row->matakuliah,
''
); //Add a row to array
}
}
if('IS_AJAX')
{
echo json_encode($data); //echo json string if ajax request
}
else
{
$this->load->view('admin/bahan_ajar/form_manage_file_view', $data); //Load html view of search results
}
}
代码它的工作好,但我想添加参数来调用数据库。
$query = $this->matakuliah_model->lookup($keyword, $id_matakuliah);
这样子。我怎么能得到
$this->input-<post('id_matakuliah')
从jquery以前。
和我有另一个文本框填充从文本框matakuliah自动完成的值。
`<input type="hidden" id="matakuliah_post" class="med" name="matakuliah_post">`
当我使用自动填充文本框自动填充另一个文本框,请帮助我。
在你的脚本'函数(REQ,加)'什么'req'的价值? – manix