-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (47 loc) · 1.8 KB
/
Copy pathscript.js
File metadata and controls
58 lines (47 loc) · 1.8 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
$(document).ready(function() {
$('#add_form').submit(function() {
event.preventDefault()
})
})
function performGetRequest1(){
var resultElement = document.getElementById('tableResult1');
resultElement.innerHTML = "";
axios.get('http://34.87.118.117/passwords')
.then(function(response){
console.log("sukses dapat data")
response.data.forEach(passwordlist => {
resultElement.innerHTML += generateSuccessTableOutput(passwordlist);
})
})
.catch(function(error){
resultElement.innerHTML = generateErrorHTMLOutput(error);
})
}
function generateSuccessHTMLOutput(response){
return '<h4>Result: </h4>' +
'<h5>Data: </h5>' +
'<pre>' + JSON.stringify(response.data, null, '\t') + '</pre>';
}
function generateSuccessTableOutput(response){
return '<tr>' +
'<td>' + response._id + '</td>'+
'<td>' + response.website + '</td>'+
'<td>' + response.email + '</td>'+
'<td>' + response.password + '</td>' +
'</tr>'
}
function createNewPasswordList () {
let inputWebsite = $('#inputWebsite').val()
let inputEmail = $('#inputEmail').val()
let inputPassword = $('#inputPassword').val()
console.log('add new', inputWebsite, inputEmail, inputPassword)
axios.post('http://34.87.118.117/passwords', {website: inputWebsite, email: inputEmail, password: inputPassword})
.then(function(response){
console.log("sukses add data");
// performGetRequest1();
})
.catch(function(error){
console.log("error add data");
resultElement.innerHTML = generateErrorHTMLOutput(error);
})
}