Ajax interview question

1. What is AJAX and how does it work?
AJAX stands for Asynchronous JavaScript and XML. It allows web pages to fetch data from the server without reloading the entire page, making the user experience smoother and faster. It uses the XMLHttpRequest (or newer fetch) API to send requests and handle responses dynamically.

2. What’s the difference between synchronous and asynchronous AJAX requests?

Synchronous requests block JavaScript execution until the response returns, making UI freeze.

Asynchronous requests let the script continue execution and handle the server response later. Asynchronous mode is preferred for better UX.

3. What is a callback function in AJAX?
A callback function is passed to the AJAX request so that it gets executed when the server response arrives. For example, you call xhr.onreadystatechange = function() { … }, and when readyState === 4 and status === 200, that callback handles the successful response.

You can also explore more questions and answers at Tpoint Tech:

(Address: Tpoint Tech – Free Online Tutorials site)