Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Blog</title>
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
- </head>
- <body>
- <h1>All Posts</h1>
- <button id="btnLoadPosts" onclick="attachEvents()">Load Posts</button>
- <select id="posts"></select>
- <button id="btnViewPost">View</button>
- <h1 id="post-title">Post Details</h1>
- <ul id="post-body"></ul>
- <h2>Comments</h2>
- <ul id="post-comments"></ul>
- <script src="./blog.js"></script>
- </body>
- </html>
- function attachEvents() {
- const URL = 'https://baas.kinvey.com/appdata/kid_Sy8W2Z0Y7';
- const USERNAME = 'Peter';
- const PASSWORD = 'p';
- const BASE_64 = btoa(USERNAME + ':' + PASSWORD);
- const AUTH = {"Authorization" : 'Basic' + BASE_64};
- $('#btnLoadPosts').on('click', loadPosts);
- function loadPosts() {
- $.ajax({
- method: 'GET',
- url: URL + 'posts',
- headers: AUTH
- }).then(function(response) {
- cosole.log(response);
- }).catch(function(error) {
- console.log(error);
- })
- }
- }
Add Comment
Please, Sign In to add comment