Jump to content

Ajax | Javascript And

) .catch(error => console.error('AJAX error:', error); statusSpan.innerHTML = '⚠️ Error checking availability'; ); ); <?php header('Content-Type: application/json'); $username = $_GET['username'] ?? '';

// In a real app, query your database $takenUsernames = ['admin', 'john', 'alice']; Javascript and AJAX

$exists = in_array(strtolower($username), $takenUsernames); ) .catch(error =&gt

// AJAX request using Fetch API (modern replacement for XMLHttpRequest) fetch('check_username.php?username=' + encodeURIComponent(username)) .then(response => response.json()) .then(data => if (data.exists) statusSpan.innerHTML = '❌ Username already taken'; statusSpan.style.color = 'red'; else statusSpan.innerHTML = '✅ Available!'; statusSpan.style.color = 'green'; statusSpan.innerHTML = '⚠️ Error checking availability'

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use