我在codeigniter中处理jquery多次自动完成意味着如果用户输入字母表然后应该显示相应的结果,如果他输入另一个输入后选择答案,那么通过添加昏迷应该相应地添加另一个结果但是当我输入任何字母表时然后没有结果以及代码不起作用。请任何人帮我解决这个问题。谢谢你...
以下是我的代码..
Js代码和HTML
<script>
$(this).ready( function() {
function split( val ) {
return val.split( /,\s'*/' );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#multiple_key_skills" ).autocomplete({
minLength: 1,
source: function(req,add ) {
//alert("ashdgd");
$.ajax({
url: "<?php echo base_url(); ?>/userdashboard/getmultiplekeyskills",
data: req,
dataType: 'json',
//type: "post",
cache: false,
success: function (data){
//alert(data);
if(data.response =="true"){
add(data.message);
console.log(data);
}
},
error: function (xhr, ajaxOptions, thrownError)
{
alert(thrownError);
}
});
},
select: function( event, ui ) {
// Add the selected term appending to the current values with a comma
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// join all terms with a comma
this.value = terms.join( ", " );
return false;
},
focus: function() {
// prevent value inserted on focus when navigating the drop down list
return false;
}
});
});
</script>
<body>
<input id="multiple_key_skills" type="text" name="multiple_key_skills">
</body>
</html>
控制器
funtion getmultiplekeyskills()
{
$keyword = $this->input->post('term');
//echo json_encode($keyword);
$query= $this -> dashboard_model-> getmultiplekeyskills($keyword);
// echo json_encode($data);
$data['response'] = 'false';
if( ! empty($query) )
{
$data['response'] = 'true'; //Set response
$data['message'] = array(); //Create array
foreach( $query as $row )
{
$data['message'][] = array(
'id'=>$row->id,
'value' => $row->key_skill,
); //Add a row to array
}
//echo json_encode("fdszf");
}
if('IS_AJAX')
{
echo json_encode($data); //echo json string if ajax request
}
else
{
$this->load->view('profile_view',$data); //Load html view of search results
}
}
}
模型
function getmultiplekeyskills()
{
$query = $this->db->query("SELECT * FROM key_skills WHERE key_skill LIKE ('$keyword%')") ;
return $query->result();
}