Open In App

What are the protocols used by Ajax ?

Last Updated : 02 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will go to cover what really Ajax means, Asynchronous, and how it makes requests to the server using XMLHTTPRequest and the protocols used by ajax, basically HTTP and HTTPS.

AJAX: AJAX stands for Asynchronous JavaScript And XML. It is about updating a web page without reloading the entire web page. This is very useful when only some parts of a web page need to be changed. It can send and receive information in various formats, including JSON, XML, HTML, and text files.

Features of Ajax:

  • Asynchronous means before completing the first request can proceed to further request to fulfill so there is no need to wait for the request to complete and the operations on the client do not get blocked. This means, that the client can work on other things and does not need to wait for the response. Examples of asynchronous calls in JavaScript are – setTimeout(), setInterval(), etc.
  • AJAX is not a programming or a scripting language. It relies on the interplay of a few different technologies and requires a little knowledge of each. 
  • The  group of inter-related technologies like JavaScript, XML, HTML, XHTML,  CSS,  JavaScript,  DOM, XML and XMLHTTPRequest. 
  • AJAX uses different protocols to exchange data between browser and server. AJAX communicates asynchronously with the server using the XMLHttpRequest object.

Protocols: Set of rules defined for communication.

AJAX mainly create request to the server for two protocols:

  • HTTP
  • HTTPs

For this request to make to the server need an instance for that XMLHTTPRequest to have the functionality to send these protocol request asynchronously

HTTP HTTP means HyperText Transfer Protocol. It is the protocol used by the World Wide Web(www) that defines how messages are formatted and transmitted. HTTP is a stateless protocol. because the server does not require to maintain information or status about every user for the duration of multiple requests and does not need to maintain a continuous connection with the client.

Features of HTTP:-

HTTP is an application layer protocol and typically uses TCP

  • Tcp  tries a retransmission when packet loss is detected .
  • Tcp header is not encrypted so http is not encrypted protocol
  • In Http communication between webservers and clients
  • HTTP work to get  requests and give responses.

HTTP is stateless protocol

  • The server opens a connection for every request and closing it after the response has been sent.
  • every request in html is completely independent 
  • In http, programming , local storage , cookies, sessions are used to create enhanced user experiences.

HTTP protocol runs on port number 80.

HTTP Headers Fields

  1. General
  2. Response 
  3. Request

Steps in HTTP requests processing –
1.Client requests a connection with the server
2.The server opens a connection with the client
3.The client makes a request to the server
4.The server processes the request
5.The server sends a response to the client
6.The client closes the connection

HTTPSHTTPS stands for Hyper Text Transfer Protocol Secure It is just a secure version of HTTP.  It uses TLS(Transport security layer)/SSL(secure socket layer) encryption over the HTTP protocol . Before request is sent , SSL encryption takes place at the transport level. So here all the request is same as HTTP. So everything in the request is encrypted. Example : credit card data , social security number etc

Features of HTTPS:

  • communication between webservers and clients
  • Http requests / responses.
  • Data sent is encrypted
  • Increase security of data transfer.
  • SSL/TSL used
  • Install certificate on web host.
  • Run on port number 443

Some cases XMLHTTPRequest also supports ftp or ftps protocol.

The types of request that you can make using HTTP/HTTPS/FTP/FTPS:

  • GET: It requests for a data.
  • HEAD: It requests for data but without the response body.
  • POST: It submits data causing a change in state on the server.            
  • PUT: It replaces the specified data with request data.
  • DELETE: It deletes the specified data.
  • CONNECT: It establishes a tunnel to the server.
  • OPTIONS: It describes the communication options for the target data.
  • TRACE: It perform message loop-back test along the path to the target data.
  • PATCH: It apply partial changes to data.

Example:

Javascript




<script>
    //create new request through constructor
    const xhrReq = new XMLHttpRequest();
     
    // Set up listener
    xhrReq.onload = () => {
     
    // Get response from the server
     let resJSON = JSON.parse(xhrReq.response);
     console.log(resJSON);
    };
     
    // Open url and get new created request
    xhrReq.open("get",
     
    // Send request to server
    xhrReq.send();
</script>


Output:

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads