[英]Fetch API cannot load localhost:3000/send. URL scheme "localhost" is not supported
I am using Node Js as backend and basic html css js for frontend.我使用 Node Js 作为后端,使用基本的 html css js 作为前端。 I am sending request through node js that
我正在通过节点 js 发送请求
app.get("/send", async (req, res) => {
let products = await Product.find();
products = await products;
res.send(products);
});
and getting fetch on an html page:并在 html 页面上获取:
const getData = async () => {
const response = await fetch("localhost:3000/send", {
method: "GET",
});
const data = await response.json();
console.log(data);
};
getData();
But i am not getting the data, I have tested the api on Postman it works fine there.但我没有得到数据,我已经在 Postman 上测试了 api,它在那里运行良好。 But throwing error on browser:
但是在浏览器上抛出错误:
Error is :错误是:
Fetch API cannot load localhost:3000/send. Fetch API 无法加载 localhost:3000/send。 URL scheme "localhost" is not supported.
不支持 URL 方案“localhost”。
Please help me out.请帮帮我。 Bundles of thanks!
多谢礼包!
您应该将 localhost 指定为http://localhost
或https://localhost
- 否则fetch
无法确定您提到的是哪个协议:
const response = await fetch("http://localhost:3000/send", { ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.