Jump to content

405 - Method not alowed.


AbbyM

Recommended Posts

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? 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.