let page = 1; let isLoading = false;
let timeoutId; document.getElementById('username').addEventListener('input', function() clearTimeout(timeoutId); let username = this.value;
) .catch(error => console.error('AJAX error:', error); statusSpan.innerHTML = '⚠️ Error checking availability'; ); );
// Parse JSON from the response return response.json(); ) .then(users => // Work with the actual JavaScript object let output = '<ul>'; users.forEach(user => output += `<li>$user.name - $user.email</li>`; ); output += '</ul>'; document.getElementById('user-list').innerHTML = output; ) .catch(error => // Handle network errors or JSON parsing errors console.error('Fetch problem:', error.message); );
stands for Asynchronous JavaScript and XML . Despite the "XML" in its name, modern AJAX commonly uses JSON (JavaScript Object Notation) instead. The core magic lies in the word Asynchronous .