HTML Web Worker and Jquery Ajax call

后端 未结 6 1226
夕颜
夕颜 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 06:51

    Since web workers are in external files, they do not have access to the following JavaScript objects:

    • The window object
    • The document object
    • The parent object

    So you can't use $ inside worker file. Better you can use traditional AJAX something like this

    if (window.XMLHttpRequest)
    {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    

    Reference at http://www.w3schools.com/html/html5_webworkers.asp

提交回复
热议问题