C#C
C#2y ago
15 replies
Whiteboy

✅ ASP.NET Fetch request to MySQL

So i want to chcek if typed login exisits in db but i get all time error 404
Error checking login existence: Error: HTTP error! Status: 404
    at 3:176:31
(anonymous)    @    3:191
Promise.catch (async)        
checkLoginExists    @    3:190
checkLogins    @    3:202
(anonymous)    @    3:208

        function checkLoginExists(login) {
            fetch(`/AssignTask/{taskId}?handler=CheckLoginExists&login=${login}`, { method: 'GET' })
                .then(response => {
                    if (!response.ok) {
                        throw new Error(`HTTP error! Status: ${response.status}`);
                    }
                    return response.json();
                })
                .then(data => {
                    const loginErrorMessage = document.getElementById('loginErrorMessage');
        
                    if (!data.exists) {
                        loginErrorMessage.textContent = `User with login '${login}' not found in the database.`;
                    } else {
                        loginErrorMessage.textContent = '';  // Clear the error message
                        enableAssignButton();
                    }
                })
                .catch(error => {
                    console.error('Error checking login existence:', error);
                    // Handle the error, e.g., display a generic error message
                });
        }

        function checkLogins(logins) {
            let loginLines = logins.split("\n");
    
            for (let i = 0; i < loginLines.length; i++) {
                let login = loginLines[i].trim();
                if (login !== "") {
                    checkLoginExists(login);
                }
            }
        }
Was this page helpful?