AJAX with jQuery
Request JSON, handle failures and update the page safely.
What you will be able to do
- Use $.getJSON for simple reads.
- Handle .fail and check response status.
- Escape data before inserting it.
- Show loading and empty states.
In plain English
$.ajax and $.getJSON wrap XMLHttpRequest with promises. They still reject on network errors, not on HTTP 404 or 500, so check status. Prefer fetch in new code, but read the old patterns confidently.
$.getJSON('/api/lessons')
.done((lessons) => {
$('#list').empty()
lessons.forEach((lesson) => $('#list').append($('<li>').text(lesson.title)))
})
.fail(() => $('#status').text('Could not load lessons'))Your turn
EasyLoad JSON
Write a $.getJSON call to /api/courses that logs the result.
JAVASCRIPT · starter
$.getJSON('/api/courses')Check your understanding before moving on.
Knowledge checkQuestion 1
Which callback runs when the request fails?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.