forked from thombergs/code-examples
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
67 lines (56 loc) · 2.58 KB
/
index.html
File metadata and controls
67 lines (56 loc) · 2.58 KB
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
<!DOCTYPE html>
<html>
<head>
<script>
function load(domainURL) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", domainURL, true);
xhttp.send();
}
function loadFromSameOrigin() {
load("http://localhost:9000/orders")
}
function loadFromCrossOrigin() {
load("http://localhost:8000/orders")
}
function updateInCrossOrigin() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
var data = {};
xhttp.open("PUT", "http://localhost:8000/orders", true);
xhttp.setRequestHeader('Content-type','application/json; charset=utf-8');
xhttp.send(JSON.stringify(data));
}
function sendAuthRequestToCrossOrigin() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhr.open('GET', "http://localhost:8000/orders", true);
xhr.setRequestHeader('Authorization', 'Bearer rtikkjhgffw456tfdd');
xhr.withCredentials = true;
xhr.send();
}
</script>
</head>
<body>
<div id="demo">
<h2>Order Processing</h2>
<div><button type="button" onclick="loadFromSameOrigin()">Fetch Orders from same Origin</button></div><br/><br/>
<div><button type="button" onclick="loadFromCrossOrigin()">Fetch Orders from different Origin (Cross Origin)</button></div><br/><br/>
<div><button type="button" onclick="updateInCrossOrigin()">Update Orders from different Origin (Cross Origin)</button></div><br/><br/>
<div><button type="button" onclick="sendAuthRequestToCrossOrigin()">Request Orders from authenticated user (Cross Origin)</button></div>
</div>
</body>
</html>