1) What is the use of XMLHttpRequest object? Explain methods that are used to send request to server using AJAX.

Use of XMLHttpRequest Object:

The XMLHttpRequest (XHR) object is a built-in JavaScript object that enables communication between a web browser and a web server. It is the core component of AJAX (Asynchronous JavaScript and XML) technology that allows web pages to update content dynamically without requiring a full page reload.

Key uses of XMLHttpRequest include:

Methods Used to Send Requests to Server Using AJAX:

1. open(method, url, async, user, password)

This method initializes a request. It specifies the HTTP method (GET, POST, etc.), the URL of the server resource, and whether the request should be asynchronous.

Example:

xhr.open("GET", "data.php", true);

2. send(data)

This method sends the request to the server. For GET requests, the parameter is typically null. For POST requests, it contains the data to be sent.

Example: