-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhrrequest.html
65 lines (59 loc) · 1.69 KB
/
xhrrequest.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
<!DOCTYPE html>
<html>
<head>
<title>XHR Trigger</title>
<style>
ul.navbar {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #f1f1f1;
overflow: hidden;
}
ul.navbar li {
float: left;
}
ul.navbar li a {
display: block;
color: #333;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
ul.navbar li a:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<ul class="navbar">
<li><a href="index.html">Home</a></li>
<li><a href="not-present-in-dom.html">Not Present in DOM</a></li>
<li><a href="not-present-in-ui.html">Not Present in UI</a></li>
<li><a href="unstable-element.html">Unstable Element</a></li>
<li><a href="disabled-element.html">Disabled Element</a></li>
<li><a href="event-receiving-element.html">Event Receiving Element</a></li>
<li><a href="xhrrequest.html">XHR Element</a></li>
<li><a href="form_elements.html">Form Element</a></li>
<li><a href="all_elements.html">All elements</a></li>
</ul>
<h2>XHR Trigger</h2>
<button id="xhrButton">Trigger XHR Call</button>
<script>
function performXHR() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://jsonplaceholder.typicode.com/posts", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("XHR call successful!");
// Handle the response here
console.log(xhr.responseText);
}
};
xhr.send();
}
var xhrButton = document.getElementById("xhrButton");
xhrButton.addEventListener("click", performXHR);
</script>
</body>
</html>