-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlistener.js
19 lines (19 loc) · 853 Bytes
/
listener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
window.onload = function () {
document.getElementById('btnSubmit')
.addEventListener('click', function () {
var xhr = new XMLHttpRequest();
xhr.open('post','/addUser');
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var userList = JSON.parse(this.responseText);
var users = '<ul>';
userList.forEach(function(user){
users+='<li>'+user['username']+'</li>';
});
users+='</ul>';
document.getElementById('usersDiv').innerHTML = users;
}
}
xhr.send('username='+document.getElementById('username').value+'&password='+document.getElementById('password').value);
});
}