Search code examples
javascripthtmlweb-worker

How can I HTML5 Web Worker return more than just one string?


At the moment, my Web Worker just returns a message as a string. Is it possible to return an object?

Thank you!


Solution

  • You can return anything, as long as it can be encoded as a string. JSON works in most cases, just like in AJAX. You can also use XML or any other format.

    You can think of Web Worker as another kind of AJAX. AJAX has a thread running in the server. Web Worker as a thread running in the client. That's the only difference. What you can pass through is text in both cases. So just think about what you would do when dealing with AJAX, and that's the way to deal with Web Worker.