Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

553
Visualizações
POST 405 (Method Not Allowed) with XMLHTTPRequest

I have been getting this error for quite a while and it's driving me crazy. I would like to send a POST request to a PHP file with ajax using XMLHTTPRequest(). This is the error that I get: Edge console

Here is my Javascript code:

function sendAndReceive(string, user) {
    let http = new XMLHttpRequest();
    let url = "http://127.0.0.1:5500/forum/js/forum.php";
    let message = "message=" + string;
    let username = "&user=" + user;
    let sendString = message + username;
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("testAJAX").innerHTML = this.responseText;
        }
    };
    console.log(sendString);
    http.send(sendString);
    document.getElementById("testAJAX").innerHTML = "Loading...";
}

I'm fairly new to Javascript so the error might be trivial. I also use the Visual Studio Code Live Server to bypass the CORS policy type errors, it might have to do with this. Also I've seen a lot of answers pointing you towards jQuery, however this is for a school project and I can't use it.

Thank You to anyone that answers.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda