首页 > 解决方案 > 从 localhost 对象获取数据发生错误

问题描述

嗨,我创建了一个后端并在 localhost 上获取它,如图所示: 在此处输入图像描述

我在codepen中获取它,但它不起作用。

  fetch(`localhost:5000/products`)
      .then(response => response.json())
      .then(data => console.log(data))
    .catch((error) => {
      console.error('Error:', error);
});

喜欢这个链接:https ://codepen.io/nutkin/pen/MWpMzMv?editors=0012

有谁知道会发生什么?

标签: jsonfetch

解决方案


嗨,我Moesif Origin & CORS Changer by Moesif在 firefox 扩展程序中安装后,它可以工作。一些后端不支持共享数据。


推荐阅读