gpt4 book ai didi

javascript - 未捕获的网络错误 : Failed to execute 'importScripts' on 'WorkerGlobalScope'

转载 作者:数据小太阳 更新时间:2023-10-29 04:21:31 29 4
gpt4 key购买 nike

我正在尝试使用 importScripts 从 web worker 导入 json 数据,出现以下错误。

Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at (my:URL to fetch data from server) failed to load.

网络 worker 代码在这里。我能够从我的网络工作线程和主 js 线程发送基本消息。我想从我的服务器从网络工作线程获取 jsonp 数据,然后回复主 js 线程。

/*web worker js file to fetch json data from server and then return to main javascript thread*/

self.onmessage = function(e)
{
var curr = setInterval(function()
{

var message = e.data;
fetchMyTournament(message);

}, 10000);
}



function fetchMyTournament(userid)
{
self.postMessage('worker saying hi');


var url = "(server URL mapping)?callback=processInfo&type=(typeOfArgument)&userId="+userid;



importScripts(url);
self.postMessage("After import script");



}
function processInfo(objJSON)
{

self.postMessage("Data returned from the server...: "
+ JSON.stringify(objJSON));
}

最佳答案

就我而言,我是这样导入 PouchDB 的:importScripts("//cdn.jsdelivr.net/pouchdb/5.3.1/pouchdb.min.js");

网址应以正确的 http/https 开头。所以改成这个解决了问题:importScripts("https://cdn.jsdelivr.net/pouchdb/5.3.1/pouchdb.min.js");

关于javascript - 未捕获的网络错误 : Failed to execute 'importScripts' on 'WorkerGlobalScope' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24349175/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com