Question

I need to make ajax calls to a REST/JSON server from javascript. Both to pull down data to the browser and to push data up. In a web worker.

Because this is in a web worker JQuery cannot be used (details here). And JQuery-hive is a library for managing web workers, not for using JQuery in a web worker (as far as I can tell from the documentation). So JQuery is not an option.

In the limited environment of a web worker, how can I make ajax calls?

Was it helpful?

Solution

Here's something to consider: jQuery is a abstraction tool: it can't do anything which isn't possible with basic JS. it might be easier with pure JS, it might be harder. But it's not magical. It just provides an abstract interface which unifies the different implementations of javascript engines in different browsers.

In this case, jQuery is an abstraction for an XMLHttpRequest. You can find a guide on how to use this on every major javascript website: w3schools.com, MDN, MSDN,... There are also many questions on stack overflow that explain how to do this.

Slightly off-topic, but this is also one of the reasons that I recommend people learning or developing javascript to first learn how to do the things manually, and only switching to a library once they've learned the basics. A library is great for abstraction, but if you haven't learned WHAT is abstracted, you get into trouble once you end up in a situation where you don't have access to the abstraction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top