Skip to content

Instantly share code, notes, and snippets.

@ratul16
Created August 8, 2019 08:50
Show Gist options
  • Save ratul16/c86217caab8cd9e20067618ff2ccdb64 to your computer and use it in GitHub Desktop.
Save ratul16/c86217caab8cd9e20067618ff2ccdb64 to your computer and use it in GitHub Desktop.
console.log("hello")
function weather() {
function weatherData(val) {
return new Promise(function (resolve, reject) {
const request = new XMLHttpRequest();
request.onload = function () {
var resData = JSON.parse(request.responseText);
console.log(resData);
resolve(resData);
};
request.onerror = function () {
reject(new Error("404 Data Not Found"));
};
request.open("GET", "weather.json", true);
request.send();
});
};
// var city = weatherData.then(data => data.city.name);
// console.log(city)
function showData() {
weatherData("weather.json").then(function (data) {
console.log(data.city.name);
document.getElementById('city').innerHTML = "<h1>" + data.city.name + "</h1>";
}).catch(function (error) {
console.log(error);
alert(" 404 Data not found !!");
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment