forked from mariusGundersen/ajax-login
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.html
43 lines (43 loc) · 1.64 KB
/
static.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
<!doctype html>
<title>static</title>
<form class="login" method="post" action="login">
<input type="hidden" name="redirectTo" value="/static.html">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">login</button> go back to this page
</form>
<form class="login" method="post" action="login">
<input type="hidden" name="redirectTo" value="/success.html">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">login</button> go to success page
</form>
<form class="login" method="post" action="login">
<input type="hidden" name="redirectTo" value="/static.html?success=true">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">login</button> go back to this page with query param
</form>
<form class="login" method="post" action="login">
<input type="hidden" name="redirectTo" value="/hidden.html">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">login</button> redirect to a page with a hidden form
</form>
<form class="login" method="post" action="login" data-push-state>
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">login</button> stay on this page but update the url with pushState
</form>
<script>
document.body.addEventListener('submit', function ajax(e){
e.preventDefault();
setTimeout(function(){
if(e.target.hasAttribute('data-push-state')){
history.pushState('title', {success:true}, "/success.html");
}else{
e.target.submit();
}
}, 1000);
}, false);
</script>