-
Notifications
You must be signed in to change notification settings - Fork 0
Add fetch api title on click #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ce45ed
add fetch api title on click
Kunal1101 79bbf69
updated marked changes
Kunal1101 5125c95
updated changes
Kunal1101 74b4ee9
fixed
Kunal1101 3239ec3
updated appenddata function to get data from fetchTodo
Kunal1101 a858311
added a helper method to pass data to appendData function
Kunal1101 a7daa00
removed async
Kunal1101 7a75e4b
add basic styling for post tile
satyam-seth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Document</title> | ||
| </head> | ||
| <style> | ||
| body { | ||
| display: grid; | ||
| place-items: center; | ||
| } | ||
| </style> | ||
| <body> | ||
| <button id="fetch-api-button">Click To Fetch</button> | ||
| <div class="append-titles"> | ||
| <h1>API Titles</h1> | ||
| </div> | ||
|
|
||
|
|
||
| <script src="./script.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| async function fetchTodo() { | ||
| try { | ||
| const response = await fetch('https://jsonplaceholder.typicode.com/todos'); | ||
| if (!response.ok) { | ||
| throw new Error('Network response was not ok'); | ||
| } | ||
| const json = await response.json(); | ||
| json.forEach((item) => { | ||
| const container = document.querySelector('.append-titles') | ||
| const newTitle = document.createElement('span') | ||
| newTitle.innerHTML = item.title; | ||
| container.appendChild(newTitle) | ||
|
|
||
| }); | ||
| } catch (error) { | ||
| console.error('There was a problem with the fetch operation:', error); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const button = document.getElementById('fetch-api-button'); | ||
| button.addEventListener('click', () => fetchTodo()) | ||
Kunal1101 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.