-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
47 lines (45 loc) · 1.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Select2 from URL</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
</head>
<body>
<select id="mySelect" style="width: 300px;"></select>
<script>
$('#mySelect').select2({
ajax: {
url: function (params) {
// Construct the search query URL based on the user's input
var searchQuery = params.term;
return 'http://localhost/rapport/index.php?option=com_jsonmaker&tmpl=component&format=raw&tableselect=medecin&term=' + searchQuery;
},
dataType: 'json',
delay: 250, // Delay requests slightly for better performance
data: function (params) {
return {
q: params.term, // Pass the search query to the server
page: params.page
};
},
processResults: function (data, params) {
// Transform the flat JSON array into Select2's expected format
return {
results: $.map(data, function (item) {
return {
id: item.id,
text: item.name
};
})
};
},
cache: true
}
});
</script>
</body>
</html>