|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <title>Sentiment Analysis Web App</title> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 7 | + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> |
| 8 | + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
| 9 | + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> |
| 10 | + |
| 11 | + <script> |
| 12 | + "use strict"; |
| 13 | + function submitForm(oFormElement) { |
| 14 | + var xhr = new XMLHttpRequest(); |
| 15 | + xhr.onload = function() { |
| 16 | + var result = parseFloat(xhr.responseText); |
| 17 | + var resultElement = document.getElementById('result'); |
| 18 | + if (result == 0) { |
| 19 | + resultElement.className = 'bg-danger'; |
| 20 | + resultElement.innerHTML = 'Your review was NEGATIVE!'; |
| 21 | + } else { |
| 22 | + resultElement.className = 'bg-success'; |
| 23 | + resultElement.innerHTML = 'Your review was POSITIVE!'; |
| 24 | + } |
| 25 | + } |
| 26 | + xhr.open (oFormElement.method, oFormElement.action, true); |
| 27 | + var review = document.getElementById('review'); |
| 28 | + xhr.send (review.value); |
| 29 | + return false; |
| 30 | + } |
| 31 | + </script> |
| 32 | + |
| 33 | + </head> |
| 34 | + <body> |
| 35 | + |
| 36 | + <div class="container"> |
| 37 | + <h1>Is your review positive, or negative?</h1> |
| 38 | + <p>Enter your review below and click submit to find out...</p> |
| 39 | + <form method="POST" |
| 40 | + action="https://lx9twcx6ni.execute-api.ap-northeast-1.amazonaws.com/prod" |
| 41 | + onsubmit="return submitForm(this);" > <!-- HERE IS WHERE YOU NEED TO ENTER THE API URL --> |
| 42 | + <div class="form-group"> |
| 43 | + <label for="review">Review:</label> |
| 44 | + <textarea class="form-control" rows="5" id="review">Please write your review here.</textarea> |
| 45 | + </div> |
| 46 | + <button type="submit" class="btn btn-default">Submit</button> |
| 47 | + </form> |
| 48 | + <h1 class="bg-success" id="result"></h1> |
| 49 | + </div> |
| 50 | + </body> |
| 51 | +</html> |
0 commit comments