Weather by API-Ninjas

부분 유료
분류별 API Ninjas Team | 업데이트됨 hace 2 meses | Weather
인기

9.8 / 10

지연 시간

644ms

서비스 수준

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 hace 2 meses

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 hace 2 meses

This code is not working

Rapid account: Studentprofessional 0
studentprofessional0 Commented hace 3 meses

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 hace 3 meses

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 hace 5 meses

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

Rapid account: Mahajanritin
mahajanritin Commented hace 6 meses

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 hace 6 meses

(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 hace 6 meses

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 hace 6 meses

also after using this its not working.

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입