-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
64 lines (58 loc) · 2.45 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Meu script -->
<script>
function enviaForm(){
var request = new XMLHttpRequest();
request.open('POST', '/post', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
console.log('enviado com sucesso')
} else {
console.log('chegou no server mas deu erro =/')
}
};
request.onerror = function() {
console.log('erro')
};
var body = mountData();
request.send(JSON.stringify(body));
}
function mountData(){
return {
fullName: document.querySelector('input[name=fullName]').value || '',
email: document.querySelector('input[name=email]').value || '',
phone: document.querySelector('input[name=phone]').value || '',
message: document.querySelector('textarea[name=message]').value || ''
}
}
</script>
</head>
<body
<div class="container">
<h1>Contato</h1>
<div>
<div class="form-group">
<label for="fullName">Nome compelto</label>
<input type="text" class="form-control" name="fullName" value="">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" value="">
</div>
<div class="form-group">
<label for="phone">Telefone</label>
<input type="phone" class="form-control" name="phone" value="">
</div>
<div class="form-group">
<label for="message">Mensagem</label>
<textarea class="form-control" name="message" rows="3"></textarea>
</div>
<input type="submit" onclick="enviaForm()" class="btn btn-default">
</div>
</div>
</body>
</html>