-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (37 loc) · 1.22 KB
/
script.js
File metadata and controls
39 lines (37 loc) · 1.22 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
let siteURL = "https://f3bbc04a-027d-4662-b0c3-314fd8a29b82-00-36k060m6zrig0.spock.replit.dev/api/nasa"
var req = new XMLHttpRequest();
req.open("GET", siteURL);
req.send();
req.addEventListener("load", function(){
if(req.status == 200 && req.readyState == 4){
let response = JSON.parse(req.responseText);
document.getElementById("BG").style.backgroundImage = `url(${response.url})`
}
})
function loginMe()
{
let un = document.getElementById("username").value
let pw = document.getElementById("password").value
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://f3bbc04a-027d-4662-b0c3-314fd8a29b82-00-36k060m6zrig0.spock.replit.dev/api/login");
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
const body = JSON.stringify({
"username": un,
"password": pw
});
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
let name = JSON.parse(xhr.responseText)
if(name == "fail")
{
alert("Invalid Account")
return;
}
localStorage.name = name
window.location.href = "user.html"
} else {
console.log(`Error: ${xhr.status}`);
}
};
xhr.send(body);
}