-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutocompleteextender
More file actions
58 lines (53 loc) · 1.36 KB
/
Autocompleteextender
File metadata and controls
58 lines (53 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// server side code
var express = require('express');
var app = express();
app.get('/', function(req, res){
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT dept_name from departments where dept_name like ' + req.query.term +'%' AS solution', function(err, rows, fields) {
if (err) throw err;
var results = [];
for (int i =0; i < rows.Length; i++)
results.push(rows[i].solution);
console.log('The solution is: %o', results);
res.send(results);
});
connection.end();
});
app.listen(8000);
<!-- clientside -->
<!-- html/css/javascript -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form>
Department:
<input type="text" id="txt_dept" style="width:100px">
</input>
</form>
<script>
jQuery("input.txt_dept").autocomplete({
source: function (request, response) {
if(validate(request.term)==false){
response([]);return;
}
jQuery.get("/autocomplete/", {
query: request.term
}, function (data) {
response(data);
});
},
minLength: 2
});
</script>
</body>
</html>