Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Books db</title>
- </head>
- <body>
- <div id="data">
- <input type="button" id="button" value="Search"/>
- <input type="text" id="search" >
- </div>
- <div id="entry">
- <br>
- <form action="http://35.184.143.37:3000/books" method="post">
- <br><br>
- <input type="text" id="title" name="title" placeholder="Enter book's title" />
- <br><br>
- <input type="text" id="author" name="author" placeholder="Enter book's author" />
- <br><br>
- <select name="genre">
- <option value="SciFi">SciFi</option>
- <option value="Satire">Satire</option>
- <option value="Drama">Drama</option>
- <option value="Action">Action/Adventure</option>
- <option value="Mystery">Mystery</option>
- <option value="Horror">Horror</option>
- </select>
- <br><br>
- <input type="text" id="price" name="price" placeholder="Enter book's price" />
- <input type="submit" value="Send message" />
- </form>
- </div>
- <script>
- document.getElementById('button').addEventListener('click',getUserInput);
- function getUserInput(event){
- var userInput = document.getElementById("search").value;
- if(userInput !== ""){
- httpGetAsync(userInput);
- }
- }
- function httpGetAsync(searchTerm){
- var theUrl =window.location + 'books?keyword=' + searchTerm;
- const xhttp = new XMLHttpRequest();
- xhttp.open("GET", theUrl, true); // true for asynchronous
- xhttp.send(null);
- xhttp.onreadystatechange = processRequest;
- function processRequest() {
- if (xhttp.readyState == XMLHttpRequest.DONE);
- var result = JSON.parse(xhttp.response);
- console.log(result);
- }}
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement