简体   繁体   English

获取 API 跨域读取阻止 (CORB) 阻止了 MIME 类型 text/html 的跨域响应

[英]Fetch API Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type text/html

Trying to fetch the data from an an api in order to display widgets on a page.尝试从 api 获取数据以在页面上显示小部件。 Here's my fetch request:这是我的提取请求:

  var protocolToUse = (location.protocol == "https:") ? "https://" : "http://";
  // url to fetch data from
  const url = `${protocolToUse}polls-api.predictinteractive.com/get/catalog`;

  fetch(url)
    // Transform data into JSON
    .then((results) => results.json())
    .then(function(data) {
      // Get the results
      let widgets = data;
      // For each widget, store their category and group name
      for (i=0; i < widgets.length; i++) {
        var category = widgets[i]["category"];
        var group = widgets[i]["group"];
        // This is the iframe link
        var src_script = `${protocolToUse}w1.predictinteractive.com/widgets/poll_widget/index.html?{"category":"${category}"}`;
        // Create a unique variable name for each widget
        var named = nameInstance();
        // The function createWidget formats the details to display the iframe and its details
        named = new createWidget(
          category,
          group,
          src_script
        );

        // This function appends each widget to an array called allWidgets
        appendToArray(named);

      }

      // Get the widget in the allWidgets array
      var firstWidget = allWidgets.shift();

      // // Append the widget to the page
      widgetContainer.appendChild(firstWidget);
    })
    .catch(function(error) {
      console.log(error);
    });

The widget iframe doesn't display, I think it might be because of this warning I'm getting in the console:小部件 iframe 不显示,我认为可能是因为我在控制台中收到此警告:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://w1.predictinteractive.com/widgets/poll_widget/index.html?{%22category%22:%22election-2020%22} with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

I'm on Homestead as well.我也在宅基地。 Let me know if I need to provide more information, I'd appreciate any and all help.如果我需要提供更多信息,请告诉我,我将不胜感激。

I'm just playing with the api at this point, i'm not really able to recreate your issue.我现在只是在玩 api,我真的无法重现你的问题。

Can you tell me which browser you use?你能告诉我你用的是什么浏览器吗? On firefox atleast i do recieve an response from the api with the data needed.至少在 Firefox 上,我确实收到了来自 api 的响应,其中包含所需的数据。

let protocolToUse = (location.protocol == "https:") ? "https://" : "http://";
const url = `${protocolToUse}polls-api.predictinteractive.com/get/catalog`;


async function fetchWídget(url) {
  const widgets = await fetch(url).then(res => res.json());
  console.log(widgets)

  for (i = 0; i < widgets.length; i++) {
    let category = widgets[i]["category"];
    let group = widgets[i]["group"];
    let src_script = `${protocolToUse}w1.predictinteractive.com/widgets/poll_widget/index.html?{"category":"${category}"}`;
    let named = nameInstance();
    named = new createWidget(
      category,
      group,
      src_script
    );
    appendToArray(named);
  }

  let firstWidget = allWidgets.shift();
  widgetContainer.appendChild(firstWidget);
}
fetchWídget(url);

EDIT: I don't have the named function, but as you can see i retrieve the data.编辑:我没有命名函数,但正如你所看到的,我检索了数据。

暂无
暂无

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

相关问题 跨域读取阻止 (corb) 阻止了 mime 类型 text/html 的跨域响应 - cross-origin read blocking (corb) blocked cross-origin response with mime type text/html 谷歌地图 api:跨源读取阻塞 (CORB) 阻止了跨源响应 - Google maps api: Cross-Origin Read Blocking (CORB) blocked cross-origin response (CORB) 阻止跨域响应 https://infinityfree.net/errors/404/ 与 MIME 类型 text/html - (CORB) blocked cross-origin response https://infinityfree.net/errors/404/ with MIME type text/html 使用MIME类型application / json的跨源读取阻止(CORB) - Cross-Origin Read Blocking (CORB) with MIME type application/json 自 2019 年 3 月 5 日起,跨域读取阻塞 (CORB) 阻止了跨域响应 - Cross-Origin Read Blocking (CORB) blocked cross-origin response since 5th March 2019 ajax发布请求-跨域读取阻止(CORB)阻止了跨源响应CORS - ajax post request - cross-Origin Read Blocking (CORB) blocked cross-origin response CORS 跨域读取阻塞 (CORB) 阻止了跨域响应 - Cross-Origin Read Blocking (CORB) blocked cross-origin response 如何在JS控制台中修复“跨域读取阻止(CORB)阻止跨源响应”? - How to fix “Cross-Origin Read Blocking (CORB) blocked cross-origin response” in the JS console? "如何解决跨域读取阻塞 (CORB) 阻止的跨域响应<URL>" - how to resolve Cross-Origin Read Blocking (CORB) blocked cross-origin response <URL> Javascript设置src属性获取错误的动态值跨源读取阻塞(CORB)阻止了跨源响应 - Javascript setting dynamic values for src attribute getting error Cross-Origin Read Blocking (CORB) blocked cross-origin response
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM