我想知道如果我可以在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