-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
79 lines (57 loc) · 2.26 KB
/
index.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!doctype html>
<html>
<head>
<title>Make Autocomplete Search with jQuery AJAX</title>
<link href="style.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="jquery-3.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#txt_search").keyup(function(){
var search = $(this).val();
if(search != ""){
search = search.replace(/(^\s+|\s+$)|\s/g,
function ($0, $1) {
return $1 ? '' : '+';
}).toLowerCase();
$.ajax({
url: 'https://t8zw3470y0.execute-api.us-east-1.amazonaws.com/prod_search?q=' + search + '~0.3&q.parser=lucene&size=20&return=_all_fields',
type: 'get',
dataType: 'json',
success:function(response){
response = response.hits.hit;
console.log(response);
var len = response.length;
$("#searchResult").empty();
for( var i = 0; i<len; i++){
var id = response[i]['fields']['f__concept_id'];
var name = response[i]['fields']['concept_name'];
$("#searchResult").append("<li value='"+id+"'>"+name+"</li>");
}
// binding click event to li
$("#searchResult li").bind("click",function(){
setText(this);
});
}
});
}
});
});
function setText(element){
var value = $(element).text();
var userid = $(element).val();
$("#txt_search").val(value);
$("#searchResult").empty();
}
</script>
</head>
<body>
<div>Enter Search </div>
<div>
<input type="text" id="txt_search" name="txt_search">
</div>
<ul id="searchResult"></ul>
<div class="clear"></div>
<div id="userDetail"></div>
</body>
</html>