Weather by API-Ninjas

FREEMIUM
От API Ninjas Team | Обновлено a month ago | Weather
Популярность

9.8 / 10

Задержка

678ms

Уровень обслуживания

100%

Health Check

N/A

Назад ко всем обсуждениям

Not working in javascript fetch if error showing async function

Rapid account: Rishabhrajvanshi 61103

async function fetchdata(){
try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.error(error);
}
}

just use this instead of the given try block it will work

Rapid account: Gauravmishragm 444
gauravmishragm444 Commented 2 months ago

I tried few solutions but now it is saying you are not subscribed to this api. i thought this was free api.

Rapid account: Shivpujankumar 02002
shivpujankumar02002 Commented 2 months ago

This code is not working

Rapid account: Studentprofessional 0
studentprofessional0 Commented 2 months ago

function getData()
{
const options = {
method: ‘GET’,
headers:
{
‘X-RapidAPI-Key’: ‘c74d28fc95msh0643089963e26c4p13a9adjsn4e3d51df13df’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

fetch(‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Karachi’)
.then(response => response.json())
.then(response => console.log(response))
.catch(response => response.error(err))

}
This is coorect workable code

Rapid account: Codingfriend 1111
codingfriend1111 Commented 2 months ago

async function fetchData() {
const url = ‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Seattle’;
const options = {
method: ‘GET’,
headers: {
‘X-RapidAPI-Key’: ‘a173513e32msh17726ed826d53c8p179137jsnb02f328154f6’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.error(error);
}
}

fetchData();

now its working i have used it
Rapid account: Malodevarsha 7
malodevarsha7 Commented 4 months ago

yes,After using all this , it is still not working

Rapid account: Mahajanritin
mahajanritin Commented 5 months ago

const url = ‘https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Seattle’;
const options = {
method: ‘GET’,
headers: {
‘X-RapidAPI-Key’: ‘98fd28b3fdmsh8db458e9d48af2cp1f26c8jsn06daa50110eb’,
‘X-RapidAPI-Host’: ‘weather-by-api-ninjas.p.rapidapi.com
}
};

async function fetchapi(){
try {
const response = await fetch(url, options);
const result = await response.text();
console.log(result);
} catch (error) {
console.log(error);
}

}

fetchapi();

Rapid account: Dexcoder 07
dexcoder07 Commented 5 months ago

(async () => {
try {
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
} catch (error) {
console.error(error);
}
})();

I suggest you try this code. It works for me.
Rapid account: Mohammadsaif 0847
mohammadsaif0847 Commented 5 months ago

try this

fetch(url, options)
.then(Response => Response.json())
.then(Response => (
console.log(Response)
))
.catch (err => console.error(err));

Rapid account: Akashsoam 123456789
akashsoam123456789 Commented 5 months ago

also after using this its not working.

Присоединяйтесь к обсуждению – добавьте комментарий ниже:

Войдите / Зарегистрируйтесь, чтобы публиковать новые комментарии