我想知道如果我可以在web工作人员文件中使用jQuery。谷歌浏览器给我这个错误:“未捕获ReferenceError:$未定义”。HTML Web工作者和jQuery的Ajax调用
下面是代码: 父文件:
var loader = new Worker(BASE_URL + "js/rss_loader_worker.js");
// Ask the worker to start loading the RSS from the server
loader.postMessage("loadRss");
// When receive the response from the server
loader.onmessage = function (event) {
console.log(event.data);
}
工人文件:
onmessage = function (event) {
if (event.data === "loadRss") {
loadRss();
}
}
/**
* This function handles the AJAX request to the server side
* then pass the content to the view page
* @param none
* @return html text
*/
loadRss = function() {
$.ajax({
data: {city: CITY_LOCATION},
url: BASE_URL + "/getfeeds",
onsucess: function (data) {
}
});
}
请帮帮忙,谢谢:)
importScripts( “的jquery.js”)使用传统的AJAX这样的事情
参考;无法工作:jQuery使用“窗口”变量,这是网络工作者无法访问的。 但是您可以使用其他库来完成这项工作=) – 2012-02-23 10:19:42
要明确入站搜索者,通过“Worker”运行ajax请求是可能的,而且通常也是有益的。由于`jQuery`是一个DOM操作库,而Web Workers具有一个`WorkerGlobalScope`而不是`Window`,因此不能访问文档或DOM,所以与传统的`jQuery`不同。 – buley 2014-04-01 23:32:15