1
0

Video 59: Wiring up the User Interface

This commit is contained in:
Jason Williams 2019-10-10 12:45:14 -06:00
parent 5c550efba9
commit 6d75e93eaf
3 changed files with 24 additions and 3 deletions

View File

@ -40,3 +40,16 @@ header a {
.portrait { .portrait {
width: 250px; width: 250px;
} }
input {
border: 1px solid #CCCCCC;
padding: 8px;
}
button {
cursor: pointer;
border: 1px solid #888888;
background: #888888;
color: #FFFFFF;
padding: 8px;
}

View File

@ -2,19 +2,24 @@ console.log('Client side javascript file is loaded!')
const weatherForm = document.querySelector('form') const weatherForm = document.querySelector('form')
const search = document.querySelector('input') const search = document.querySelector('input')
const messageOne = document.querySelector('#message-1')
const messageTwo = document.querySelector('#message-2')
weatherForm.addEventListener('submit', (e) => { weatherForm.addEventListener('submit', (e) => {
e.preventDefault() e.preventDefault()
const location = search.value const location = search.value
messageOne.textContent = 'Loading...'
messageTwo.textContent = ''
fetch('/weather?address=' + location).then((response) => { fetch('/weather?address=' + location).then((response) => {
response.json().then((data) => { response.json().then((data) => {
if (data.error) { if (data.error) {
console.log(data.error) messageOne.textContent = data.error
} else { } else {
console.log(data.location) messageOne.textContent = data.location
console.log(data.forecast) messageTwo.textContent = data.forecast
} }
}) })
}) })

View File

@ -18,6 +18,9 @@
<input placeholder="Location"> <input placeholder="Location">
<button>Search</button> <button>Search</button>
</form> </form>
<p id="message-1"></p>
<p id="message-2"></p>
</div> </div>
{{>footer}} {{>footer}}