|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <script> |
| 5 | + function load(domainURL) { |
| 6 | + var xhttp = new XMLHttpRequest(); |
| 7 | + xhttp.onreadystatechange = function() { |
| 8 | + if (this.readyState == 4 && this.status == 200) { |
| 9 | + document.getElementById("demo").innerHTML = this.responseText; |
| 10 | + } |
| 11 | + }; |
| 12 | + xhttp.open("GET", domainURL, true); |
| 13 | + xhttp.send(); |
| 14 | + } |
| 15 | + |
| 16 | + function loadFromSameOrigin() { |
| 17 | + load("http://localhost:9000/orders") |
| 18 | + } |
| 19 | + |
| 20 | + function loadFromCrossOrigin() { |
| 21 | + load("http://localhost:8000/orders") |
| 22 | + } |
| 23 | + |
| 24 | + function updateInCrossOrigin() { |
| 25 | + var xhttp = new XMLHttpRequest(); |
| 26 | + xhttp.onreadystatechange = function() { |
| 27 | + if (this.readyState == 4 && this.status == 200) { |
| 28 | + document.getElementById("demo").innerHTML = this.responseText; |
| 29 | + } |
| 30 | + }; |
| 31 | + var data = {}; |
| 32 | + |
| 33 | + xhttp.open("PUT", "http://localhost:8000/orders", true); |
| 34 | + xhttp.setRequestHeader('Content-type','application/json; charset=utf-8'); |
| 35 | + |
| 36 | + xhttp.send(JSON.stringify(data)); |
| 37 | + } |
| 38 | + |
| 39 | + function sendAuthRequestToCrossOrigin() { |
| 40 | + var xhr = new XMLHttpRequest(); |
| 41 | + xhr.onreadystatechange = function() { |
| 42 | + if (this.readyState == 4 && this.status == 200) { |
| 43 | + document.getElementById("demo").innerHTML = this.responseText; |
| 44 | + } |
| 45 | + }; |
| 46 | + xhr.open('GET', "http://localhost:8000/orders", true); |
| 47 | + xhr.setRequestHeader('Authorization', 'Bearer rtikkjhgffw456tfdd'); |
| 48 | + xhr.withCredentials = true; |
| 49 | + xhr.send(); |
| 50 | + } |
| 51 | + |
| 52 | + </script> |
| 53 | + |
| 54 | + |
| 55 | + </head> |
| 56 | +<body> |
| 57 | + |
| 58 | +<div id="demo"> |
| 59 | + <h2>Order Processing</h2> |
| 60 | + <div><button type="button" onclick="loadFromSameOrigin()">Fetch Orders from same Origin</button></div><br/><br/> |
| 61 | + <div><button type="button" onclick="loadFromCrossOrigin()">Fetch Orders from different Origin (Cross Origin)</button></div><br/><br/> |
| 62 | + <div><button type="button" onclick="updateInCrossOrigin()">Update Orders from different Origin (Cross Origin)</button></div><br/><br/> |
| 63 | + <div><button type="button" onclick="sendAuthRequestToCrossOrigin()">Request Orders from authenticated user (Cross Origin)</button></div> |
| 64 | +</div> |
| 65 | + |
| 66 | +</body> |
| 67 | +</html> |
0 commit comments