Detect a failed jQuery AJAX request

$.ajax({
    url: '/basket/add',
    type: 'POST',
    data: { sku: sku, qty: 1 },
    timeout: 8000
}).fail(function (jqXHR, textStatus) {
    // textStatus is 'timeout', 'abort', 'parsererror' or 'error';
    // only the last one has a status code worth reading.
    showError(textStatus === 'timeout' ? 'Still trying...' : 'Could not add that.');
});