[英]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.