Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <title>TODO supply a title</title>
  10. <meta charset="UTF-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12. </head>
  13. <body>
  14. <div>
  15. <button>Procitaj</button>
  16. </div>
  17. <script>
  18. function fAjax() {
  19. //kreiranje objekta request
  20. var req = new XMLHttpRequest();
  21.  
  22. // provera onready...svojstva kroz anonimus funkciju
  23. req.onreadystatechange = (function () {
  24. // da li je zahtev obradjen i odgovor spreman???
  25. if (req.readyState === 4 && req.status === 200) {
  26. console.log(req.responseText);// sadrzaj odgovora od strane web servera
  27. document.write(`<p>${req.responseText}</p>`);
  28. }
  29. });
  30. req.open('GET', 'mojfajl.txt', true);
  31. req.send();
  32. }
  33. // uzimamo prvi taster
  34. var taster = document.getElementsByTagName('button')[0];
  35. taster.addEventListener('click', fAjax);
  36. </script>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement