AbbyM Posted September 25, 2022 Share Posted September 25, 2022 I am creating a contact form using php. This is what the app.js code looks like const form = document.querySelector('form'); statusTxt = form.querySelector('.button__area span'); form.onsubmit = (e) => { e.preventDefault() statusTxt.style.display = "block" var xhttp = new XMLHttpRequest(); // create xml object xhttp.open("POST", "message.php", true); xhttp.onload = () => { if (xhttp.readyState == 2 && xhttp.status == 200) { let response = xhttp.response; console.log(response) } } xhttp.send(); } the php code is just supposed to echo sth: <?php echo "This message is from message.php" ?> However, I am getting this error: I understand it has to do with the headers, but I have no idea how to edit them to allow a post request. app.js:18 POST http://127.0.0.1:5500/message.php 405 (Method Not Allowed) How do i about it? Quote Link to comment https://forums.phpfreaks.com/topic/315369-405-method-not-alowed/ Share on other sites More sharing options...
Barand Posted September 25, 2022 Share Posted September 25, 2022 Moved to JS forum Quote Link to comment https://forums.phpfreaks.com/topic/315369-405-method-not-alowed/#findComment-1601041 Share on other sites More sharing options...
requinix Posted September 25, 2022 Share Posted September 25, 2022 That's not headers. You have something in place that is preventing the request, and you're the only one who would be able to find out what it is. Check your server or PHP logs for a hint. In the meantime, 1. Why use POST if you're not sending anything? Use GET. 2. XMLHttpRequest is so last decade. Use fetch. Quote Link to comment https://forums.phpfreaks.com/topic/315369-405-method-not-alowed/#findComment-1601043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.