-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistro.js
56 lines (36 loc) · 1.29 KB
/
registro.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
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener("DOMContentLoaded", load, false);
checkToken();
function checkToken(){
tokenUsu = sessionStorage.getItem("token");
if(tokenUsu != null){
window.location.href = "boards.html";
}
}
function load(){
submitEvent();
}
function submitEvent(){
let form = document.getElementById("formCadastro");
form.addEventListener("submit", function(e){
e.preventDefault();
var url = "http://tads-trello.herokuapp.com/api/trello/users/new";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var obj = JSON.parse(this.responseText);
$("#modalSuccess").modal("show");
}
if (this.readyState == 4 && this.status == 400) {
alert("Usuario ja cadastrado");
}
}
let dados = {
name: document.getElementById("name").value,
username: document.getElementById("username").value,
password: document.getElementById("password").value
};
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(JSON.stringify(dados));
})
}