Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

549
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!