Skip to content

Working with AJAX

  • AJAX (Asynchronous JavaScript and XML) is a web development technique that allows web applications to send and retrieve data from a server asynchronously without reloading the entire webpage.
  • This creates faster, more dynamic, and interactive user experiences by updating only specific parts of the page.
  • AJAX is not a programming language but a concept that combines several technologies. While traditionally the XMLHttpRequest object was used, the modern Fetch API has largely replaced it due to its simplicity and flexibility.

  1. Asynchronous communication: Requests are made in the background, allowing users to continue interacting with the page while the server processes requests.
  2. Partial page updates: Only relevant parts of the page are updated, making interactions faster and smoother.
  3. Technology combination: AJAX combines JavaScript, XMLHttpRequest/Fetch API, HTML/CSS, and data exchange formats like JSON or XML.

  1. Triggering event: The user interacts with the web page (clicking a button, typing in a search field, keypress, page scroll, etc.).
  2. AJAX request: JavaScript uses XMLHttpRequest or Fetch API to send an HTTP request to the server asynchronously.
  3. Server processing: The server receives and processes the request, then sends back a response (typically JSON).
  4. Page update: JavaScript receives the response and updates the relevant part of the webpage via DOM manipulation.

Search without page reload:

  1. You type a search query and click “Search”.
  2. JavaScript sends (sometimes as you type) the search term to the server via AJAX.
  3. The server processes the search and returns results in JSON format.
  4. JavaScript updates the page to display the search results.

  • Faster interactions: Only required data is retrieved, eliminating full page reloads.
  • Better user experience: Real-time updates and seamless interactions without page freezing.
  • Reduced server load: Smaller data packets instead of entire page assets.
  • Dynamic updates: Specific page sections update independently.

  • Real-time data fetching: Google Maps, weather apps, and live dashboards.
  • Live search: Search suggestions that appear as you type.
  • Form validation: Real-time checking (email availability, password strength).
  • Chat applications: Sending and receiving messages without page refresh.
  • Social media feeds: Infinite scrolling and live-updating content.