-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
58 lines (55 loc) · 1.76 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
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
</head>
<body>
<h3>
<a href="https://developers.google.com/recaptcha/docs/v3">
reCAPTCHA v3
</a>
</h3>
<form action="/signin" method="POST">
<input type="submit" value="Submit">
</form>
<div id="result"></div>
<script src="https://www.google.com/recaptcha/api.js?render=your_site_key"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
var fetchToken = () => new Promise((resolve, reject) =>{
grecaptcha.ready(function () {
grecaptcha.execute('your_site_key', {
action: 'homepage'
}).then(function (token) {
console.log("g-recaptcha-response", token);
resolve(token);
});
});
});
var send = ()=>{
fetchToken().then(token=>{
let data = {
"other": "post data ...",
"token": token,
};
let jsonData = JSON.stringify(data);
let url = "/signin";
$.ajax({
method: "POST",
url: url,
data: jsonData
}).done(function (msg) {
$("#result").html(msg.message)
});
});
}
$(function () {
$("form").submit(function (event) {
event.preventDefault();
$("#result").html("loading")
send();
})
});
</script>
</body>
</html>