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
- Create a folder with
index.html,app.jsanddata.json. Put{"message":"Hello, AJAX"}in data.json. - In index.html add a paragraph with
id="result"and load app.js using a script tag with defer. - Save the JavaScript below as app.js. Start the static-file server from this folder.
- 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.1Expected 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.