Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

546
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda