-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
script.js
45 lines (42 loc) · 1.17 KB
/
script.js
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
$(document).ready(function() {
$('#turnOnBtn').on('click', function(e){
$.ajax({
url: '/led?status=on',
method: 'GET',
success: function(result) {
console.log(result);
}
});
e.preventDefault();
});
$('#turnOffBtn').on('click', function(e){
$.ajax({
url: '/led?status=off',
method: 'GET',
success: function(result) {
console.log(result);
}
});
e.preventDefault();
});
$('#btnToggle').on('click', function(e){
let status;
if($(this).text() == 'Turn On') {
$(this).text('Turn Off')
$(this).removeClass().addClass('btn btn-block btn-light');
status = 'on';
} else {
$(this).text('Turn On');
$(this).removeClass().addClass('btn btn-block btn-dark');
status = 'off';
}
$.ajax({
url: '/led?status=' + status,
method: 'GET',
success: function(result) {
console.log(result);
}
});
e.preventDefault();
});
});