Pedophilicus_gonicus

TUTORIAL #8 CLIENT

Nov 19th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getQuery(){
  2.     let parameters = ["artist","name","minattack","maxattack","minhealth","maxhealth","cardClass","rarity"];
  3.     req = new XMLHttpRequest();
  4.     req.responseType = "json";
  5.     req.onreadystatechange = function() {
  6.         if(this.readyState == 4 && this.status == 200){
  7.             updatePage(this.response.info);
  8.         }
  9.     }
  10.     send =`?`;
  11.     parameters.forEach(param =>{
  12.         if(document.getElementById(param).value){
  13.             send+=`${param}=${document.getElementById(param).value}&`;
  14.         }
  15.     });
  16.     send = send.slice(0, -1);
  17.     req.open("POST", "http://localhost:3000/cards" + send);
  18.     //remeber to parse min and max health and shit in the server
  19.     req.send();
  20. }
  21.  
  22. function updatePage(info){
  23.     let results = document.getElementById("results");
  24.     for(let i = 0;i < info.length; i++){
  25.         let atag = document.createElement("a");
  26.         atag.href = "http://localhost:3000/cards/" + info[i]._id;
  27.         atag.innerHTML = info[i].name;
  28.         results.append(atag);
  29.         results.append(document.createElement("br"));
  30.     }
  31. }
Add Comment
Please, Sign In to add comment