Skip to content

Commit 737352c

Browse files
committed
Replace main.js with a new implementation that consolidates data fetching and event handling for improved clarity and functionality.
1 parent f99d166 commit 737352c

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

app/src/main/assets/js/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
window.addEventListener('DOMContentLoaded', () => {
2+
console.log('DOMContentLoaded-----')
3+
const getdata = document.querySelector('#getdata')
4+
getdata.addEventListener('click', (e) => {
5+
e.preventDefault()
6+
console.log('getdata')
7+
fetch('https://api.github.com/users/octocat')
8+
.then((response) => response.json())
9+
.then((data) => {
10+
console.log('data', data)
11+
const greetMsgEl = document.querySelector('#greet-msg')
12+
greetMsgEl.textContent = data.login
13+
})
14+
.catch((error) => {
15+
console.error('error', error)
16+
})
17+
})
18+
})

app/src/main/assets/main.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)