I want to get object from this link:
http://api.weatherapi.com/v1/current.json?key=281c886ff27d4f7cb57182453221607&q=Tehran&aqi=no
I wanna save it on variable.
I wanna do it all on javascript (frond-end). I don't want Node.js Code.
for example save it like this:
const my_weather = {
location: {
...
},
...
};
i wanna use it on my html page
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline
const url = 'http://api.weatherapi.com/v1/current.json?key=281c886ff27d4f7cb57182453221607&q=Tehran&aqi=no';
fetch(url)
.then((response) => {
console.log(response);
});
If jquery is allowed, you can use getJSON to do it
const url = 'http://api.weatherapi.com/v1/current.json?key=281c886ff27d4f7cb57182453221607&q=Tehran&aqi=no';
$.getJSON(url, response => {
console.log(response);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>