title: XMLHttpRequest() POST returns 405 error; method not allowed
body: <p>My html code:</p>
  <pre><code>    &lt;h2&gt;Please finalize your details&lt;/h2&gt;
      &lt;form id=&quot;details&quot; method=&quot;post&quot; class=&quot;form&quot;&gt;
  
          Full name: &lt;strong name=&quot;name_1&quot;&gt;ABCDEF&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
          ID No:&lt;strong name=&quot;org_number_1&quot;&gt;123&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
          Mobile No:&lt;strong name=&quot;ph_number_1&quot;&quot;&gt;1234567890&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
          
          E-mail: &lt;strong name=&quot;email_1&quot;&gt;ABC@DEF.COM&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
          ID Card: &lt;img src=&quot;profile.png&quot; alt=&quot;preview&quot; name=&quot;image&quot; style=&quot;width: 100px; height: 100px;&quot;&gt;&lt;br&gt;&lt;br&gt;
  
          &lt;button id=&quot;go&quot;&gt;It's correct&lt;/button&gt;
          
      &lt;/form&gt;
  </code></pre>
  <p>My javascript:</p>
  <pre><code>document.getElementById('go').addEventListener('click', submit);
  function submit(){
  
      var nme=document.getElementsByName(&quot;name_1&quot;)[0].innerHTML;
      var id=document.getElementsByName(&quot;org_number_1&quot;)[0].innerHTML;
      var phone=document.getElementsByName(&quot;ph_number_1&quot;)[0].innerHTML;
      var email=document.getElementsByName(&quot;email_1&quot;)[0].innerHTML;
      var img=document.getElementsByName(&quot;image&quot;)[0].src;
  
      const xhr=new XMLHttpRequest();
  
      xhr.onload=function(){
  
          const serverResponse=document.getElementById(&quot;response&quot;);
          serverResponse.innerHTML=this.responseText;
      };
  
      xhr.open(&quot;POST&quot;, &quot;database_registration.php&quot;);
      xhr.setRequestHeader(&quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;);
      xhr.send(&quot;name=&quot;+nme+&quot;&amp;id=&quot;+id+&quot;&amp;phone=&quot;+phone+&quot;&amp;email=&quot;+email+&quot;&amp;img=&quot;+img); //this line throws the error &quot;Failed to load resource: the server responded with a status of 405 (Method Not Allowed)&quot;
  }
  </code></pre>
  <p>I am executing my code in <strong>Visual Studio Code editor</strong> and my project location is in:</p>
  <blockquote>
  <p>C:\Users\Abhishek\Desktop\Web-dev stuff\XAMPP\htdocs\Stack hack 20 20</p>
  </blockquote>
  <p>This is the error:</p>
  <p><a href="https://i.stack.imgur.com/R1PbP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R1PbP.png" alt="enter image description here" /></a></p>
  <p>Not only that, I've also tried working with <strong>Fetch API</strong>, but it throws the same error too. What do I do now? How can I make it work?</p>