AJAX 可以使用 HTTP 或 HTTPS 之外的协议吗?

发布于 2024-11-14 12:47:13 字数 43 浏览 4 评论 0原文

我想知道 AJAX 是否可以使用 HTTP 或 HTTPS 之外的协议。

I wonder if AJAX can use protocols other than HTTP or HTTPS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2024-11-21 12:47:13

Ajax 意味着 XMLHttpRequest。正如您不必将 XML 与 XHR 一起使用一样,您也不必使用 HTTP。

尽管名称如此,XMLHttpRequest 可用于检索任何类型的数据,而不仅仅是 XML,并且它支持除 HTTP 之外的协议(包括 fileftp)。

来自 W3C XMLHttpRequest 规范(添加了重点):

XMLHttpRequest 对象实现由脚本引擎公开的接口,该引擎允许脚本执行 HTTP 客户端功能,例如提交表单数据或从服务器加载数据。它是 ECMAScript HTTP API。

为了与 Web 兼容,该对象的名称是 XMLHttpRequest,尽管该名称的每个组成部分都可能产生误导。首先,该对象支持任何基于文本的格式,包括 XML。其次,它可用于通过 HTTP 和 HTTPS 发出请求(某些实现还支持除 HTTP 和 HTTPS 之外的协议,但本规范未涵盖该功能)。最后,它支持广义上的“请求”,因为它涉及 HTTP;即与定义的 HTTP 方法的 HTTP 请求或响应相关的所有活动。

HTTP 和 HTTPS 之外的可用协议都是非标准化的,因此它们取决于您所使用的特定环境1。也就是说,所有兼容的 XHR 实现都必须支持 HTTP 和 HTTPS,但不要求支持任何其他特定协议。这意味着您可能会发现 Internet Explorer 支持


1例如哪个版本的浏览器(Safari、Firefox、Chrome、IE vs Opera) vs...),或者哪种服务器端实现(V8 vs Rhino vs...)

Ajax means XMLHttpRequest. Just as you don't have to use XML with XHR, you also don't have to use HTTP.

Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just XML, and it supports protocols other than HTTP (including file and ftp).

From the W3C XMLHttpRequest spec (emphasis added):

The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server. It is the ECMAScript HTTP API.

The name of the object is XMLHttpRequest for compatibility with the Web, though each component of this name is potentially misleading. First, the object supports any text based format, including XML. Second, it can be used to make requests over both HTTP and HTTPS (some implementations support protocols in addition to HTTP and HTTPS, but that functionality is not covered by this specification). Finally, it supports "requests" in a broad sense of the term as it pertains to HTTP; namely all activity involved with HTTP requests or responses for the defined HTTP methods.

The available protocols beyond HTTP and HTTPS are non-standardized, so they depend on the specific environment1 you're using. That is, all compliant XHR implementations must support HTTP and HTTPS, but are not required to support any other specific protocols. That means that you might find that Internet Explorer supports


1Such as, which version of which browser (Safari vs Firefox vs Chrome vs IE vs Opera vs...), or which server-side implementation (V8 vs Rhino vs...)

酷炫老祖宗 2024-11-21 12:47:13

XMLHttpRequest (XHR) 是可用于 Web 浏览器脚本语言(例如 JavaScript)的 API。它用于向 Web 服务器发送 HTTP 或 HTTPS 请求并将服务器响应数据加载回脚本中。

来自维基百科

XMLHttpRequest (XHR) is an API available to web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests to a web server and load the server response data back into the script.

from wikipedia

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文