-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (62 loc) · 1.98 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
65
66
67
68
69
70
71
72
73
74
<html>
<head>
</head>
<body>
<center>
<h3>What is Rares saying now?</h3>
<div>
<img style="height:50%;width:30%;" src="http://i.imgur.com/sJVWbu3.jpg" alt="Einstein"><br/>
<button id="request">Click me</button>
<div id="bio"></div></center>
</div>
</body>
<script>
(function() {
'use strict';
// find the desired selectors
var btn = document.getElementById('request');
var bio = document.getElementById('bio');
// set up a request
var request = new XMLHttpRequest();
// keep track of the request
request.onreadystatechange = function() {
// check if the response data send back to us
if(request.readyState === 4) {
// add a border
bio.style.border = '1px solid #e8e8e8';
// uncomment the line below to see the request
// console.log(request);
// check if the request is successful
if(request.status === 200) {
// update the HTML of the element
bio.innerHTML = request.responseText;
} else {
// otherwise display an error message
bio.innerHTML = 'An error occurred during your request: ' + request.status + ' ' + request.statusText;
}
}
}
var http = new XMLHttpRequest();
var url = "http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=cyf";
var params = "Hello World";
/* http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);*/
// specify the type of request
request.open('GET', 'http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=cyf');
// register an event
btn.addEventListener('click', function() {
// hide the button
this.style.display = 'none';
// send the request
request.send();
});
})();
</script>
</html>