How do you handle Ajax errors in jQuery?

<p>Page</p>
$.getJSON('missing.json')
  .done(function () { console.log('ok'); })
  .fail(function (xhr, status, error) {
    console.log('Failed: ' + xhr.status + ' ' + error);
  })
  .always(function () { console.log('Request finished'); });
Console output

Failed: 404 Not Found
Request finished

Also set a timeout, show a message to the user and log the details. See jQuery Ajax.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.