Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>title</title>
  7.  
  8. <script>
  9.  
  10. var callbackWhenDataGetsBack = function (data) {
  11. console.log(JSON.parse(data));
  12. }
  13.  
  14. function loadData(httpMethod, url, callback) {
  15. console.log("preparing request");
  16.  
  17. var xhr = new XMLHttpRequest();
  18.  
  19. xhr.onreadystatechange = function () {
  20. if (xhr.readyState === 4) {
  21. console.log("data received");
  22. callback(xhr.response);
  23. }
  24. }
  25.  
  26. xhr.open(httpMethod, url, true);
  27. xhr.send('');
  28. console.log("sent");
  29. }
  30.  
  31.  
  32. function loadUsers(callbackForReceivingUsers) {
  33. loadData('GET', "https://kartoteka-project.firebaseio.com/users.json", callbackForReceivingUsers)
  34. }
  35.  
  36.  
  37. function loadExercises(callbackForReceivingExercises) {
  38. loadData('GET', "https://kartoteka-project.firebaseio.com/exercises.json", callbackForReceivingExercises)
  39. }
  40.  
  41.  
  42. window.onload = function () {
  43. loadUsers(callbackWhenDataGetsBack);
  44. };
  45. </script>
  46. </head>
  47.  
  48. <body>
  49. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  50. crossorigin="anonymous"></script>
  51. </body>
  52.  
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement