而rubyzip現在(2013/8/30)已更新成版本1.0.0。1.0.0就不再有zip/zip、zip/zipfilesystem 這兩個檔案。
所以解決方法是在Gemfile加入版本指定即可:
gem 'rubyzip', "~> 0.9.9"
$.getJSON( "search.php", {term: extractLast( request.term )}, response );$.getJSON是使用GET方式,與Codeigniter預設是不開放GET有衝突到,所以要解決這個問題有兩種做法:$aryPara = array(
$this->input->post('term') //抓term(使用者所輸入的值)
);
$sql = "SELECT col1 FROM table1 WHERE col1 LIKE CONCAT(?, '%');";
$result = $this->db->query($sql, $aryPara);
if($result->num_rows() > 0){
$data= array(); //一定要轉成有label及value的array
foreach($result->result() as $row){
//設定資料, col1替換成你的欄位名稱
$data[] = array('label'=> $row->col1, 'value'=> $row->col1);
}
}
echo json_encode($data);
$result->free_result();
$this->db->close();
$("#txtKeyword").bind("keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active ) {
event.preventDefault();
}
})
.autocomplete({
source: function(request, response) {
$.ajax({url: "search.php",
//注意:這裡是設定post的變數及值,Server端就是以這個變數名稱取值
data: {term: extractLast( request.term )},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
search: function() {
var term = extractLast(this.value);
if (term.length < 2 ) { //當字數小於兩個字時,不抓資料
return false;
}
},
focus: function() {return false;},
select: function(event, ui) {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast(term) {
return split( term ).pop();
}
這樣就大功告成了。