w1coding.comAll tutorials

AJAX Environment Setup

AJAX lessons
  1. Environment Setup
  2. Introduction To AJAX
  3. Introduction To AJAX
  4. How AJAX Works
  5. Setting Up An HTML Page For AJAX
  6. Using Xmlhttprequest
  7. Sending A Get Request
  8. Handling Server Response
  9. Post Requests With AJAX
  10. AJAX And JSON
  11. AJAX Error Handling
  12. AJAX With PHP
  13. AJAX With Node.js
  14. AJAX With Python Flask
  15. Form Submission Using AJAX
  16. AJAX And XML
  17. AJAX With jQuery
  18. AJAX And JavaScript Promises
  19. Cross Domain Requests
  20. AJAX Caching Techniques
  21. Polling With AJAX
  22. AJAX Long Polling
  23. AJAX And REST Apis
  24. AJAX File Upload
  25. AJAX Loading Spinner
  26. AJAX And Session Management
  27. Pagination With AJAX
  28. Filtering Data Using AJAX
  29. AJAX Search Autocomplete
  30. Chained Dropdowns With AJAX
  31. AJAX In Single Page Applications
  32. Best Practices In AJAX

AJAX is a technique for making web requests from JavaScript. Use a local HTTP server so your page and practice data share an origin.

What you need

  • A browser with Developer Tools
  • A text editor
  • Python for a simple static-file server

Set up your environment

  1. Create a folder with index.html, app.js and data.json. Put {"message":"Hello, AJAX"} in data.json.
  2. In index.html add a paragraph with id="result" and load app.js using a script tag with defer.
  3. Save the JavaScript below as app.js. Start the static-file server from this folder.
  4. Open http://127.0.0.1:8000/. In Developer Tools, inspect the Network panel to see the request to data.json.

Your first check

Save as app.js

fetch('data.json')
  .then(response => {
    if (!response.ok) throw new Error('Request failed');
    return response.json();
  })
  .then(data => { document.querySelector('#result').textContent = data.message; })
  .catch(error => console.error(error));

Run or verify

python -m http.server 8000 --bind 127.0.0.1

Expected result: The paragraph displays Hello, AJAX and data.json has a successful response in Network.

Common setup problems

  • Use the HTTP address rather than double-clicking the HTML file.
  • Python http.server serves static files. PHP examples need a PHP server, and other backend examples need their own matching runtime.

Official documentation

Guide reviewed 17 November 2026. Check the linked vendor documentation for current supported versions and operating systems.