Home › JavaScript Tutorial › JS AJAX
JS AJAX
Older way to load data.
AJAX updates part of a page without reloading. XMLHttpRequest is the old API; fetch is the modern one. Requests here are blocked, so errors are handled.
Example code
<p id='o'>Loading...</p>
<script>
const x=new XMLHttpRequest();
x.onload=()=>o.textContent='Status '+x.status;
x.onerror=()=>o.textContent='Blocked in preview (works on your site)';
x.open('GET','https://jsonplaceholder.typicode.com/todos/1');x.send();
</script>