Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let inputSearch = document.querySelector('.filterPosts');
- let pList = document.querySelector('.postsList');
- let requestURL = 'Posts.json';
- let request = new XMLHttpRequest();
- request.open('GET', requestURL);
- request.responseType = 'json'; request.send();
- request.onload = function() {
- let posts = request.response;
- showPosts(posts);
- }
- function showPosts(jsonObj) {
- let posts = jsonObj['posts'];
- for (let i = 0; i < posts.length; i++) {
- let listContent = document.createElement('a');
- listContent.textContent = posts[i].name;
- listContent.href = posts[i].url;
- let liItem = document.createElement('li');
- liItem.appendChild(listContent);
- pList.appendChild(liItem);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement