Advertisement
max2201111

template/index.html

Jun 11th, 2024 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | Science | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Translate</title>
  7.     <script>
  8.         function translateTerm() {
  9.             const term = document.getElementById('translateTerm').value;
  10.             fetch('/translate', {
  11.                 method: 'POST',
  12.                 headers: {
  13.                     'Content-Type': 'application/json'
  14.                 },
  15.                 body: JSON.stringify({ term: term })
  16.             })
  17.             .then(response => response.json())
  18.             .then(data => {
  19.                 const translationDiv = document.getElementById('translation');
  20.                 if (data.success) {
  21.                     translationDiv.textContent = data.translation;
  22.                     translationDiv.style.display = 'block';
  23.                 } else {
  24.                     translationDiv.textContent = data.error;
  25.                     translationDiv.style.display = 'block';
  26.                 }
  27.             });
  28.         }
  29.     </script>
  30. </head>
  31. <body>
  32.     <h1>Translate</h1>
  33.     <textarea id="translateTerm" placeholder="Enter term to translate"></textarea>
  34.     <button onclick="translateTerm()">Translate</button>
  35.     <div id="translation" style="display:none;"></div>
  36. </body>
  37. </html>
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement