forked from cloudacademy/static-website-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajaxdemo.html
68 lines (53 loc) · 1.56 KB
/
ajaxdemo.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
65
66
67
68
<!DOCTYPE html>
<head>
<style type="text/css">
iframe {
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
}
</style>
<script type="text/javascript">
window.addEventListener('message', function(text){
try {
console.log('Got message');
console.log(text);
document.getElementById('captchaFrame').style.visibility = 'hidden';
} catch (e){
console.log(e);
}
}, false);
window.onload = function(){
document.getElementById('button').addEventListener('click', function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', "/ajax_info.txt", true);
xhr.withCredentials = true;
xhr.onreadystatechange = function(){
console.log(xhr.readyState + ' ' + xhr.status)
if ((xhr.readyState == 4) && (xhr.status == 456)){
alert("Received a 456 from origin. Show CAPTCHA form");
if (document.getElementById('captchaFrame')){
document.getElementById('captchaFrame').parentNode.removeChild(document.getElementById('captchaFrame'))
}
var iframe = document.createElement('IFRAME');
iframe.id = 'captchaFrame'
iframe.src = "/distil_r_captcha.html"
document.body.appendChild(iframe)
} else if (xhr.readyState == 4){
alert('Response: ' + xhr.status)
}
}
xhr.send("p=abcdefg");
})
}
</script>
<script src="/bot-protection.js" async></script>
</head>
<body>
<input type="submit" id="button" name="Click me" value="Click me" style="width: 400px; height: 100px">
<br><br>
<input type="text" name="input_headers"/>
</body>
</html>