HTML Web Worker and Jquery Ajax call

后端 未结 6 1227
夕颜
夕颜 2020-11-30 06:19

I\'m wondering if I can use jQuery inside the web worker file. Google Chrome gives me this error: \"Uncaught ReferenceError: $ is not defined\".

Here is the code: Th

6条回答
  •  盖世英雄少女心
    2020-11-30 07:00

    No you cannot. There's no access to non-thread safe components or the DOM and you have to pass specific data in and out of a thread through serialized objects. So you have to work really hard to cause problems in your code. jQuery is a JavaScript DOM library.

    But you can use a native XMLHttpRequest in your worker however.

    And, importing external scripts does not go via the page with a script tag : use importScripts() for that in your worker file.

提交回复
热议问题