forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
28 lines (26 loc) · 916 Bytes
/
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
<body>
<button id="load">Make request</button> <button id="delayed-load">Make delayed request</button>
<pre id="output"></pre>
<script>
const makeRequest = () => {
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://jsonplaceholder.cypress.io/posts")
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
const data = {
title: 'example post',
body: 'this is a post sent to the server',
userId: 1
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
document.getElementById('output').innerText = xhr.response
}
}
xhr.send(JSON.stringify(data))
}
document.getElementById('load').addEventListener('click', makeRequest)
document.getElementById('delayed-load').addEventListener('click', () => {
setTimeout(makeRequest, 1000)
})
</script>
</body>