JSFiddle - React, Tailwind, and code Playground
by Ty
HTML
<input type='text' id='userInput' placeholder='Input message here'></input>
<button id='getWeather'>Get Weather</button>
<div id='results'>Results should go Here!</div>
JavaScript
//AJAX
$(document).ready(function () {
$('#userInput').keydown(function () {
if (event.keyCode == 13) {
var City = $('#userInput').val();
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?q=' + City,
success: function (theWeather) {
var sunrise = (theWeather.sys.sunrise)
var sunset = (theWeather.sys.sunset)
$('#results').html(Math.round((theWeather.main.temp) - 273.15));
}
});
$('#results').text('Running!');
}
});
});