Coding Global Background
Coding Global

Error 405 Method Not Allowed

Archived 2 years ago
3 messages
1 members
2 years ago
Open in Discord
0
VIPER

So basically no matter what I do I still get the same error over and over which is 405 Method Not Allowed ```js document.addEventListener("DOMContentLoaded", function () { const submitButton = document.getElementById("submit-button"); const messageElement = document.getElementById("message"); submitButton.addEventListener("click", function () { console.log("Button clicked"); // Add this line const usernameInput = document.getElementById("username-input"); const keyInput = document.getElementById("key-input"); const passwordInput = document.getElementById("password-input"); const username = usernameInput.value; const key = keyInput.value; const password = passwordInput.value; // Make an AJAX request to db.php using a POST request const xhr = new XMLHttpRequest(); xhr.open("POST", "../includes/db.php", true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { const response = xhr.responseText; if (response === 'UserLoggedIn') { // Key is valid, user logged in messageElement.innerText = 'Logged in successfully!'; } else { // Some error occurred messageElement.innerText = 'Error: ' + response; } } else { // Handle HTTP error messageElement.innerText = 'HTTP Error: ' + xhr.status; } } }; // Send the data to db.php xhr.send(`username=${encodeURIComponent(username)}&key=${encodeURIComponent(key)}&password=${encodeURIComponent(password)}`); }); }); ``` It is this line ```js xhr.send(`username=${encodeURIComponent(username)}&key=${encodeURIComponent(key)}&password=${encodeURIComponent(password)}`);``` and ik it's javascript I tried using fetch aswell literally anything I do it gives me that error

Replies (3)