Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.97 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>Load Posts</title>
  5.     <script src="jquery-3.0.0.min.js"></script>
  6. </head>
  7. <body>
  8.     <button id="loadPosts">Load Posts from Kinvey</button>
  9.     <script>
  10.         $('#loadPosts').click(function() {
  11.             let USERNAME = "guest"
  12.             let PASSWORD = "123"
  13.             let authBase64 = btoa(USERNAME + ":" + PASSWORD)
  14.             $.ajax({
  15.                 method: "GET",
  16.                 url: "https://baas.kinvey.com/appdata/kid_S1b_XoIB/knigi",
  17.                 headers: {"Authorization": "Basic " + authBase64 },
  18.                 success: showPosts,
  19.                 error: showError
  20.                
  21.             })
  22.         })
  23.  
  24.         function showPosts(data, status) {
  25.             let ul = $('<ul>')
  26.             for (let post of data) {
  27.               ul.append($('<li>').text(
  28.                 post.title + " -> " + post.body));
  29.             }              
  30.         $('body').append(ul);
  31.         }
  32.  
  33.  
  34.         function showError(data,status) {
  35.                 let errorMsg = "Error: " + data.responseText;
  36.                 $('body').append($('<div>').text(errorMsg));
  37.             }
  38.        
  39.     </script>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement