Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var login = document.getElementById("login");
- var modal = document.getElementById('myModal');
- var btn = document.getElementById("signup");
- var signUp = document.getElementById("signUpTwo");
- const PORT = 5001;
- const API_BASE_URL = `http://localhost${PORT ? ":" + PORT : ""}`;
- window.onload = function(){
- const xhr = new XMLHttpRequest;
- xhr.withCredentials = true;
- const url = `${API_BASE_URL}/stuff`;
- // We needed to add a callback function to handle the response!
- xhr.onreadystatechange = function () {
- if (this.readyState == 4 && this.status == 200) {
- console.log(xhr.responseText);
- }
- };
- xhr.open("GET",url,true);
- xhr.send();
- }
- login.addEventListener("click",function(){
- var name = document.getElementById("username").value;
- var pass = document.getElementById("password").value;
- const xhr = new XMLHttpRequest;
- xhr.withCredentials = true;
- const url = `${API_BASE_URL}/check?username=${name}&password=${pass}`;
- xhr.onreadystatechange = function () {
- if (this.readyState == 4 && this.status == 200) {
- console.log(xhr.responseText);
- }
- };
- xhr.open("POST",url,true);
- xhr.send();
- })
- signUp.addEventListener("click",function(){
- var username = document.getElementById("signUpUsername").value;
- var email = document.getElementById("signUpEmail").value;
- var password = document.getElementById("signUpPassword").value;
- console.log(username + " " + password + " " + email);
- const xhr = new XMLHttpRequest;
- const url = `${API_BASE_URL}/signUp`;
- xhr.onreadystatechange = function () {
- if (this.readyState == 4 && this.status == 200) {
- console.log(xhr.responseText);
- }
- };
- xhr.open("POST",url,true);
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.send("username="+username+"&password="+password+"&email="+email);//"username="+username+"&password="+password+"&email="+email
- })
- btn.onclick = function() {
- modal.style.display = "block";
- }
- window.onclick = function(event) {
- if (event.target == modal) {
- modal.style.display = "none";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement