Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Per-request error handling with timeout $.ajax({ url : '/api/data', method : 'GET', timeout: 5000 // 5 seconds }) .done(function (data) { render(data); }) .fail(function (xhr, status, err) { if (status === 'timeout') { alert('Request timed out. Check your connection.'); } else { alert('Error ' + xhr.status + ': ' + xhr.statusText); } }); // Global spinner using AJAX events $(document) .on('ajaxStart', function () { $('#spinner').show(); }) .on('ajaxStop', function () { $('#spinner').hide(); }) .on('ajaxError', function (e, xhr) { console.error('Global AJAX error:', xhr.status); });
Result
Open