2019-10-10 18:13:01 +00:00
|
|
|
console.log('Client side javascript file is loaded!')
|
|
|
|
|
2019-10-10 18:30:22 +00:00
|
|
|
const weatherForm = document.querySelector('form')
|
|
|
|
const search = document.querySelector('input')
|
2019-10-10 18:45:14 +00:00
|
|
|
const messageOne = document.querySelector('#message-1')
|
|
|
|
const messageTwo = document.querySelector('#message-2')
|
2019-10-10 18:30:22 +00:00
|
|
|
|
|
|
|
weatherForm.addEventListener('submit', (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
const location = search.value
|
|
|
|
|
2019-10-10 18:45:14 +00:00
|
|
|
messageOne.textContent = 'Loading...'
|
|
|
|
messageTwo.textContent = ''
|
|
|
|
|
2019-10-10 18:30:22 +00:00
|
|
|
fetch('/weather?address=' + location).then((response) => {
|
|
|
|
response.json().then((data) => {
|
|
|
|
if (data.error) {
|
2019-10-10 18:45:14 +00:00
|
|
|
messageOne.textContent = data.error
|
2019-10-10 18:30:22 +00:00
|
|
|
} else {
|
2019-10-10 18:45:14 +00:00
|
|
|
messageOne.textContent = data.location
|
|
|
|
messageTwo.textContent = data.forecast
|
2019-10-10 18:30:22 +00:00
|
|
|
}
|
|
|
|
})
|
2019-10-10 18:13:01 +00:00
|
|
|
})
|
|
|
|
})
|