-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.js
32 lines (31 loc) · 945 Bytes
/
posts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
async function fetchUserPost() {
const urlParams = new URLSearchParams(window.location.search);
const userId = urlParams.get("id");
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts?userId=${userId}`
);
const userData = await response.json();
try {
userData.forEach((data) => {
userDatatoCard(data);
});
} catch (error) {
alert("Bir Sorunla Karşılaşıldı:" + error);
}
}
function userDatatoCard(userPost) {
const postRow = document.getElementById("postRow");
const div = document.createElement("div");
div.innerHTML = `
<div class="card">
<div class="card-body">
<div class="card-text">Post Title :<span class="text-success">${userPost.title}</span></div>
<div class="card-text">Post Description : <span>${userPost.body}</span></div>
</div>
</div>
`;
postRow.appendChild(div);
}
window.onload = function () {
fetchUserPost();
};