Created
August 8, 2019 08:50
-
-
Save ratul16/c86217caab8cd9e20067618ff2ccdb64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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