admin管理员组文章数量:1333210
While trying to fetch images from cloudinary getting this error 'TypeError: Failed to fetch'. Its a MERN project.
const fetchPosts = async () => {
setLoading(true);
try {
const response = await fetch("http://localhost:8080/api/v1/post", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (response.ok) {
const result = await response.json();
setAllPosts(result.data.reverse());
}
} catch (err) {
alert(err);
} finally {
setLoading(false);
}
};
While trying to fetch images from cloudinary getting this error 'TypeError: Failed to fetch'. Its a MERN project.
const fetchPosts = async () => {
setLoading(true);
try {
const response = await fetch("http://localhost:8080/api/v1/post", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (response.ok) {
const result = await response.json();
setAllPosts(result.data.reverse());
}
} catch (err) {
alert(err);
} finally {
setLoading(false);
}
};
Share
Improve this question
edited Feb 15, 2023 at 20:48
mmh4all
1,7614 gold badges8 silver badges23 bronze badges
asked Feb 15, 2023 at 11:38
Kiran JohnsonKiran Johnson
311 gold badge1 silver badge4 bronze badges
3 Answers
Reset to default 2Failed to fetch issue is the most probably because of CORS , please make sure that your backend should allow requests from your domain. Also please check the response that has been sending from backend api.
This is likely an issue with what you're receiving from the backend. Check CORS headers, the HTTP method the backend expects, the URL, etc.
See this link for some more possible answers:
https://bobbyhadz./blog/javascript-typeerror-failed-to-fetch-cors
My IP address wasn't added to mongodb, once it was added the issue got resolved.
本文标签: javascriptGetting this error message 39TypeError Failed to fetch39Stack Overflow
版权声明:本文标题:javascript - Getting this error message 'TypeError: Failed to fetch' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742286082a2446953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论