我怎样才能使一个网络工作者一个Ajax调用? [英] How can I make an ajax call in a web worker?

查看:149
本文介绍了我怎样才能使一个网络工作者一个Ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要AJAX调用从JavaScript的一个REST / JSON服务器。这两个数据下拉到浏览器,并推数据了。在一个网络工作者。

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.

由于这是在一个网络工作者JQuery的不能使用(详细这里)。和jQuery巢是一个用于管理网络工作者,而不是在一个网络工作者使用JQuery库(据我可以告诉从文档)。所以,jQuery是不是一种选择。

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.

在一个网络工作者有限的环境下,如何才能让Ajax调用?

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

推荐答案

下面是要考虑的事情:jQuery是一个抽象的工具:它不能做任何事情,这是不可能的基本JS。它可能是用纯的JS容易,可能有困难。但是,这并不神奇。它只是提供了一个抽象的接口,统一的JavaScript引擎的不同实现在不同的浏览器。

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.

在这种情况下,jQuery是用于XMLHtt prequest的抽象。你可以找到如何使用此对每一个主要的JavaScript的网站指南: w3schools.com MDN ,的 MSDN ,......还有的 http://stackoverflow.com/questions/tagged/xmlhtt$p$pquest">many问题解释如何做到这一点。

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.

稍微偏离主题,但是这也是我推荐大家学习或开发JavaScript来先学会如何手工做的事情,只有切换到库后,他们已经学会了基本的原因之一。图书馆是伟大的抽象,但是如果你没有学到过什么是抽象的,你遇到麻烦,一旦你最终在一个情况下,你没有访问到抽象。

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.

这篇关于我怎样才能使一个网络工作者一个Ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆