jQuery AJAX
AJAX loads data from a server without reloading the page. jQuery has $.ajax, $.get, $.post and $.getJSON. The calls return promise-like objects with .done(), .fail() and .always(). This page cannot reach a real server, so the example shows the code and fakes the response with a Deferred; on a real site the first block is all you write.
$.getJSON("/api/users/1")
.done(function (user) { $("#name").text(user.name); })
.fail(function () { $("#name").text("Could not load"); });
Examplehtml
Quick check
Which jQuery method is used to handle a failed request?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.