简体   繁体   English

Fetch API 无法加载 localhost:3000/send。 不支持 URL 方案“localhost”

[英]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://localhosthttps://localhost - 否则fetch无法确定您提到的是哪个协议:

const response = await fetch("http://localhost:3000/send", { ... });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 fetch api 无法加载,不支持 url 方案“文件” - fetch api cannot load, url scheme 'file' is not supported 使用Fetch API POST到localhost:3000 - POST with Fetch API to localhost:3000 如何修复“由于访问控制检查,Fetch API 无法加载 http://localhost:3000/static/js/0.chunk.js” - How to fix 'Fetch API cannot load http://localhost:3000/static/js/0.chunk.js due to access control checks' XMLHttpRequest无法加载http:// localhost:3000 / get - XMLHttpRequest cannot load http://localhost:3000/get 无法使用 Fetch API 从本地主机加载 Deezer API 资源 - Cannot load Deezer API resources from localhost with the Fetch API Next.js/Square API 错误:Fetch API 无法加载。 不支持 URL 方案“webpack-internal” - Next.js/Square API error: Fetch API cannot load. URL scheme "webpack-internal" is not supported XMLHttpRequest无法加载“此URL”来源Access:Control-Allow-Origin不允许使用原始http:// localhost:3000。 - XMLHttpRequest cannot load “THIS URL” Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. React fetch('http:// localhost:3000 / profile /:id') - React fetch('http://localhost:3000/profile/:id') 发布 localhost:3000/api/users 404 未找到 - Post localhost:3000/api/users 404 not found CORS 策略已阻止从源“http://localhost:3000”访问“https://localhost:7144/api/employees” - Access to fetch at 'https://localhost:7144/api/employees' from origin 'http://localhost:3000' has been blocked by CORS policy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM