Need Pull Data Json File Display Html Page Using Typescript Javascript Im Working Angular Q37139331

I need to pull data from a JSON file and display it on an htmlpage using typescript/javascript. Im working in angular


Solution


You have not shared the source of JSON file.. So, i am sharing acode which i created for my own use with JSON from openweatherwebsite’s API:

<!DOCTYPE html><html lang = “en”><head><title>Sky Map</title><meta charset = “utf-8″ /><script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”></script></head><body><script>$(document).ready(function () {$(‘#btnGetWeather’).click(function () {var resultElement = $(‘#resultDiv’);resultElement.html(”);var requestData = $(‘#txtCity’).val() + ‘,’ + $(‘#txtCountry’).val();$.ajax({url: ‘http://api.openweathermap.org/data/2.5/weather’,method: ‘get’,data: { q: requestData, appid:’2b92ac90c161a8b52a86175509113de9′, units:’metric’},dataType: ‘json’,success: function (response) {if (response.message != null) {resultElement.html(response.message);}else {if(response.main.temp < 50) {$(‘body’).css(‘background-color’, ‘#2aa3fb’);} else {$(‘body’).css(‘background-color’, ‘#e0e419’);}resultElement.html(‘Temp: ‘ + response.main.temp + ‘<br/>’

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.