1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
$("#search").keyup("input", function(e) {
var val = $(this).val();
if(val === "") return;
//You could use this to limit results
if(val.length < 3) return;
console.log(val);
$.get("/test/examples/recupererListFilms.php?films="+encodeURIComponent(val), function(res) {
var dataList = $("#searchresults");
dataList.empty();
console.log(res);
if(res.Films.length) {
for(var i=0, len=res.Films.length; i<len; i++) {
var opt = $("<option></option>").attr("value", res.Films[i][0])
.attr("data-id", res.Films[i][1]);
dataList.append(opt);
}
}
},"json");
}); |
Partager