login.ejs
2.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>로그인</title>
<!--=======Font Open Sans======-->
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<!--=======Custom Style======-->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="form-box">
<div class="head">GPS 기반 자유시장 로그인</div>
<form action="/email/ajax" id="login-form" method="post">
<div class="form-group">
<label class="label-control">
<span class="label-text">Email</span>
</label>
<input type="email" name="email" class="form-control" />
</div>
<div class="form-group">
<label class="label-control">
<span class="label-text">Password</span>
</label>
<input type="password" name="password" class="form-control" />
</div>
<input type="submit" value="로그인" class="btn" id ="ajaxsend" />
<p class="text-p"> <%= message %> </p>
</form>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
$('.form-group input').on('focus blur', function (e) {
$(this).parents('.form-group').toggleClass('active', (e.type === 'focus' || this.value.length > 0));
}).trigger('blur');
});
</script>
<script>
document.querySelector('#ajaxsend').addEventListener('click', function () {
var email = document.getElementsByName('email')[0].value
var password = document.getElementsByName('password')[0].value
sendAjax('http://localhost:3000/login', {'email':email,'password': password})
})
function sendAjax(url, data) {
data = JSON.stringify(data);
//alert(data);
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', "application/json");
xhr.send(data);
xhr.addEventListener('load', function () {
console.log(xhr.responseText);
var result = JSON.parse(xhr.responseText);
var resultDiv = document.querySelector(".result");
if(result.email) {
//resultDiv.innerHTML = "Welcome, " + result.email + "!!";
window.location.href ="/map"
}
else window.location.href ="/login"//resultDiv.innerHTML = result;
//document.querySelector(".result").innerHTML = result.name;
})
}
</script>
</body>
</html>