Guest User

Untitled

a guest
Sep 30th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Blog</title>
  6. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  7. </head>
  8. <body>
  9. <h1>All Posts</h1>
  10. <button id="btnLoadPosts" onclick="attachEvents()">Load Posts</button>
  11. <select id="posts"></select>
  12. <button id="btnViewPost">View</button>
  13. <h1 id="post-title">Post Details</h1>
  14. <ul id="post-body"></ul>
  15. <h2>Comments</h2>
  16. <ul id="post-comments"></ul>
  17. <script src="./blog.js"></script>
  18. </body>
  19. </html>
  20.  
  21. function attachEvents() {
  22. const URL = 'https://baas.kinvey.com/appdata/kid_Sy8W2Z0Y7';
  23. const USERNAME = 'Peter';
  24. const PASSWORD = 'p';
  25. const BASE_64 = btoa(USERNAME + ':' + PASSWORD);
  26. const AUTH = {"Authorization" : 'Basic' + BASE_64};
  27.  
  28. $('#btnLoadPosts').on('click', loadPosts);
  29.  
  30. function loadPosts() {
  31. $.ajax({
  32. method: 'GET',
  33. url: URL + 'posts',
  34. headers: AUTH
  35. }).then(function(response) {
  36. cosole.log(response);
  37. }).catch(function(error) {
  38. console.log(error);
  39. })
  40. }
  41. }
Add Comment
Please, Sign In to add comment