kema

Untitled

Jun 22nd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
  6.     <title>Call Kinvey with AJAX and jQuery</title>
  7. </head>
  8. <body>
  9.     <button id="loadPosts" onclick="callKinvey()">Load Posts from Kinvey</button>
  10.     <script>
  11.     function callKinvey() {
  12.         $.ajax({
  13.             method: "GET",
  14.             url: "https://baas.kinvey.com/appdata/kid_BkUg26LS/posts",
  15.             headers: { "Authorization": "Basic " + btoa("pena:pena")
  16.             },
  17.  
  18.             //data: { … },
  19.         success: function(data, status) {
  20.             showPosts(data);
  21.         },
  22.         error: function(data, status) {
  23.             $('body').append(JSON.stringify(data));
  24.         }
  25.     });
  26.  
  27.     }
  28.         function showPosts(posts) {
  29.             for (let p of posts) {
  30.                 $('body').append($('<div class="title">').text(p.title))
  31.                 $('body').append($('<div class="body">').text(p.body));
  32.             }
  33.  
  34.         }
  35.  
  36.     </script>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment