Can AJAX use protocols other than HTTP or HTTPS?

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

+4
source share
2 answers

Ajax stands for XMLHttpRequest . Just as you do not need to use XML with XHR, you also do not need to use HTTP.

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

From the W3C XMLHttpRequest specification (highlighted by me):

The XMLHttpRequest object implements an interface exposed by a scripting mechanism that allows scripts to perform HTTP client functions, such as sending form data or downloading data from a server. This is the ECMAScript HTTP API.

The object name is XMLHttpRequest for Internet compatibility, although each component of this name is potentially misleading. First, the object supports any text format, including XML. Secondly, it can be used for HTTP and HTTPS requests ( some implementations support protocols in addition to HTTP and HTTPS, but this functionality does not apply to this specification ). Finally, it supports โ€œrequestsโ€ in the broad sense of the term, since it refers to HTTP; Namely, all actions related to HTTP requests or responses for specific HTTP methods.

Available protocols outside of HTTP and HTTPS are not standardized, so they depend on the specific environment 1 you are using. That is, all compatible XHR implementations must support HTTP and HTTPS, but are not required to support any other specific protocols. This means that you may find that Internet Explorer supports


1 For example, which browser version (Safari vs Firefox vs Chrome vs IE vs Opera vs ...), or which is on the server side (V8 vs Rhino vs ...)

+8
source

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

from wikipedia

-4
source

All Articles