title: AJAX Post to AWS API Gateway not working (405 Method not allowed), but its working with Postman
body: <p>I built a small HTML form with bootstrap and I'm hosting it as a static Website in an AWS S3 Bucket. Then I added an AWS API Gateway and Lamda function so that the data from this form is stored into an AWS DynamoDB.</p>
  <p>At this point, I can &quot;Post&quot; raw JSON Data via Postman to the API Gateway and the Lambda function is storing the data in the DynamoDB table. I created a .ajax in my Website to gather the data and send it as JSON. But I always get this error:</p>
  <p><img src="https://i.stack.imgur.com/VqgvY.png" alt="enter image description here" /></p>
  <p>My AJAX:</p>
  <pre><code>$(document).ready(function(){
  $(&quot;#form&gt;button[type=submit]&quot;).click(function(event){
      event.preventDefault();
  
      let apiGatewayInvokeURL = 'https://gxt8igxck7.execute-api.eu-central-1.amazonaws.com/dev/test';
      
      var body = {
      KundenID : $(&quot;#KundenID&quot;).val(), 
      Vorname : $(&quot;#Vorname&quot;).val(), 
      Nachname : $(&quot;#Nachname&quot;).val(),
      Telefonnummer : $(&quot;#Telefonnummer&quot;).val(),
      Email : $(&quot;#Email&quot;).val(),
      Strasse : $(&quot;#Strasse&quot;).val(),
      Hausnummer : $(&quot;#Hausnummer&quot;).val(),
      PLZ : $(&quot;#PLZ&quot;).val(),
      Ort : $(&quot;#Ort&quot;).val(),
      Ankunftszeit : $(&quot;#Ankunftszeit&quot;).val(),
      Abreisezeit : $(&quot;#Abreisezeit&quot;).val(),
      datencheck : $(&quot;#datencheck&quot;).val() 
      };
  
      $.ajax({
          type: 'POST',
          url : apiGatewayInvokeURL,
          crossDomain: 'true',
          contentType: 'application/json; charset=utf-8',
          data: JSON.stringify(body),
  
          success: function () {
              $(&quot;#form&quot;).trigger('reset');
              alert('Successfull');
             },
          error: function (response) {
                alert('Failed: HTTP ' + response.status);
            }
            });  
         });
   });
  </code></pre>
  <p>I just can't seem to find the reason for this error. The API Gateway can clearly handle POST requests, but maybe I got the wrong idea about what I'm doing. If you need any further data just let me know.</p>
  <p>Thanks in advance!</p>
  <p><strong>EDIT</strong></p>
  <p>Here is the Network Tab of Chrome while submitting:</p>
  <p><img src="https://i.stack.imgur.com/n10pM.png" alt="enter image description here" /></p>
  <p>It seems the Post request is going to the S3 Bucket Server instead of the API Gateway?
  And Content-Type of my Request Header is application/x-www-form-urlencoded, shouldn't it be application/json?</p>
  <p><strong>EDIT LAST</strong></p>
  <p>Found the Error.. apparently</p>
  <pre><code>$(&quot;#form&gt;button[type=submit]&quot;).click(function(event)
  </code></pre>
  <p>was not working as intended. Because of this</p>
  <pre><code>event.preventDefault();
  </code></pre>
  <p>was not called correctly and the form natively POSTED to the Website HOST which is S3 Bucket and is not allowing POST Requests. I changed the Code to</p>
  <pre><code>    $(&quot;#btn&quot;).click(function(event){
      event.preventDefault();
  </code></pre>
  <p>Now it's working like a charm after fixing some minor CORS errors.
  Maybe this helps someone</p>