Quiero obtener un objeto de este enlace:
http://api.weatherapi.com/v1/current.json?key=281c886ff27d4f7cb57182453221607&q=Teherán&aqi=no
Quiero guardarlo en variable.
Quiero hacerlo todo en javascript (frontal). No quiero código Node.js.
por ejemplo guardarlo así:
const my_weather = { location: { ... }, ... };quiero usarlo en mi página html
La API Fetch proporciona una interfaz de JavaScript para acceder y manipular partes de la canalización HTTP
const url = 'http://api.weatherapi.com/v1/current.json?key=281c886ff27d4f7cb57182453221607&q=Tehran&aqi=no'; fetch(url) .then((response) => { console.log(response); });Si se permite jquery, puede usar getJSON para hacerlo
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>