Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Books db</title>
  5.     </head>
  6.  
  7.  
  8.  
  9.  
  10.     <body>
  11.         <div id="data">
  12.             <input type="button" id="button" value="Search"/>
  13.             <input type="text" id="search" >
  14.         </div>
  15.         <div id="entry">
  16.             <br>
  17.             <form action="http://35.184.143.37:3000/books" method="post">
  18.             <br><br>
  19.             <input type="text" id="title" name="title" placeholder="Enter book's title" />
  20.             <br><br>
  21.             <input type="text" id="author" name="author" placeholder="Enter book's author" />
  22.             <br><br>
  23.             <select name="genre">
  24.                  <option value="SciFi">SciFi</option>
  25.                  <option value="Satire">Satire</option>
  26.                  <option value="Drama">Drama</option>
  27.                  <option value="Action">Action/Adventure</option>
  28.                  <option value="Mystery">Mystery</option>
  29.                  <option value="Horror">Horror</option>
  30.             </select>
  31.             <br><br>
  32.             <input type="text" id="price" name="price" placeholder="Enter book's price" />
  33.             <input type="submit" value="Send message" />
  34.             </form>
  35.         </div>
  36.        
  37.         <script>
  38.             document.getElementById('button').addEventListener('click',getUserInput);
  39.             function getUserInput(event){
  40.                 var userInput = document.getElementById("search").value;
  41.                 if(userInput !== ""){
  42.                     httpGetAsync(userInput);
  43.                 }
  44.             }
  45.  
  46.             function httpGetAsync(searchTerm){
  47.                 var theUrl =window.location + 'books?keyword=' + searchTerm;
  48.                 const xhttp = new XMLHttpRequest();
  49.                 xhttp.open("GET", theUrl, true); // true for asynchronous
  50.                 xhttp.send(null);
  51.                 xhttp.onreadystatechange = processRequest;
  52.  
  53.                 function processRequest() {
  54.        
  55.                     if (xhttp.readyState == XMLHttpRequest.DONE);
  56.                     var result = JSON.parse(xhttp.response);
  57.                     console.log(result);
  58.             }}
  59.  
  60.         </script>
  61.  
  62.     </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement