I would like to create a page which can only be accessed by people who have entered their details. To do this, the browser does GET /checkout
and sends the authorisation information in the header, which will either return the hidden page to the browser or will return a different page for the user to enter their details. Once they have entered their details (for the first time), they are sent to the server and a session token as well as a user id are generated and returned. This is then stored to the session storage. Is there a way to display this page sent in the response from the webserver by using a GET
request using AJAX?
function checkoutLogin() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = a => {
if (a.target.readyState === XMLHttpRequest.DONE && a.target.status === 200) {
console.log("nice");
//response received successfully
//display the page now
}
}
xmlhttp.open("GET", "/checkout");
xmlhttp.setRequestHeader("Content-Type", "html; charset=UTF-8");
xmlhttp.setRequestHeader("userID", sessionStorage.getItem("ID"));
xmlhttp.setRequestHeader("sessionToken", sessionStorage.getItem("Hash"));
xmlhttp.send();
}