Advertisement
Guest User

zaSasho

a guest
Jun 28th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Using AJAX</title>
  6. <script src="jquery-3.0.0.js">
  7. </script>
  8. </head>
  9.  
  10. <body>
  11. <button id="loadPosts">Load Posts from Kinvey</button>
  12. <script>
  13. $('#loadPosts').click(function() {
  14. let USERNAME = "guest"
  15. let PASSWORD = "guest"
  16. $.ajax({
  17. method: "GET", // POST
  18. url: "http://baas.kinvey.com/appdata/kid_r1e5bvKS/books",
  19. headers: {"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD) },
  20. success: function(data, status) {
  21. let ul = $('<ul>')
  22. for (let post of data) {
  23. ul.append($('<li>').text(post.Title + " -> " + post.Author + " -> " + post.Description));
  24. }
  25. $('body').append(ul);
  26. },
  27. error: function(data, status) {
  28. let errorMsg = "Error: " + data.responseText;
  29. $('body').append($('<div>').text(errorMsg));
  30. }
  31. });
  32. });
  33. </script>
  34.  
  35.  
  36.  
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement