AJAX (Asynchronous JavaScript and XML) in JavaScript allows for asynchronous communication with the server. It enables web applications to send and retrieve data from the server in the background, without interfering with the display and behavior of the existing page.
Example:
// Make an AJAX request
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// action when response is received
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();