title: The POST method is not supported for this route. Supported methods: GET, HEAD. - {Ajax, jQuery, Laravel}
body: <p>I'm trying to delete an image using a button click. I'm using jQuery ajax to send the post request to the back end and the back end is Laravel. I'm triggering the POST request when the button is clicked and I'm not using a form. I'm not sure if this is the correct approach. Any ideas/suggestions are greatly appreciated.</p>
  <p>Here's my <strong>html code</strong></p>
  <pre><code>&lt;div class=&quot;deal-images-in-new-deal-modal&quot; id=&quot;deal-images-after-uploading-section&quot; style=&quot;display:flex; justify-content: center; padding:10%; flex-wrap: wrap;&quot;&gt; 
    &lt;div class=&quot;new-deal-upload-image&quot;&gt;                                 
      &lt;img src=&quot;&quot; width=&quot;150&quot; height=&quot;150&quot;&gt;                              
    &lt;/div&gt;                             
    &lt;div class=&quot;new-deal-upload-icon&quot;&gt;                                 
      &lt;button type=&quot;submit&quot; class=&quot;btn delete_image_button&quot; id=&quot;after_image_upload_0&quot; value=&quot;151159&quot;&gt;                                     
        &lt;i class=&quot;trash icon&quot; id=&quot;after_image_upload&quot; style=&quot;color:red;&quot;&gt;&lt;/i&gt;                                 
      &lt;/button&gt;                             
    &lt;/div&gt; 
    &lt;div class=&quot;new-deal-upload-image&quot;&gt;                                 
      &lt;img src=&quot;&quot; width=&quot;150&quot; height=&quot;150&quot;&gt;                              
    &lt;/div&gt;                             
    &lt;div class=&quot;new-deal-upload-icon&quot;&gt;                                 
      &lt;button type=&quot;submit&quot; class=&quot;btn delete_image_button&quot; id=&quot;after_image_upload_1&quot; value=&quot;151160&quot;&gt;                                     
        &lt;i class=&quot;trash icon&quot; id=&quot;after_image_upload&quot; style=&quot;color:red;&quot;&gt;&lt;/i&gt;                                
     &lt;/button&gt;                             
    &lt;/div&gt; 
    &lt;div class=&quot;success-message&quot;&gt;Test&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Here's the <strong>JS script file</strong></p>
  <pre><code>$(document).on('click', '.delete_image_button',function(e) {
      e.preventDefault();
     var image_id = $(this).val();
  
  
      $.ajax({
          type: &quot;POST&quot;,
          url: '/deals/delete-image/'.image_id,
          dataType: 'JSON',
          success: function(data) {
              console.log(&quot;inside success fuction&quot;, data);
              html = &quot;&lt;div id='success-message'&gt;The image id is &quot;+data+&quot;&lt;/div&gt;&quot;;
              $('.success-message').replaceWith(html);
          }
      });
  });
  </code></pre>
  <p>Here's the route in the Laravel Routes file
  <strong>Routes.php</strong></p>
  <pre><code>Route::post('deals/delete-image/{image_id}','MainController@deleteImages');
  </code></pre>
  <p>Here's the code laravel controller file</p>
  <p><strong>MainController.php</strong></p>
  <pre><code>public function deleteDealImages($image_id) {
          \Log::info(&quot;inside deleteDealImages function in back end&quot;);
          return $image_id;
      } 
  </code></pre>
  <p>I'm getting 405 status code with error response as</p>
  <pre><code>{
      &quot;message&quot;: &quot;The POST method is not supported for this route. Supported methods: GET, HEAD.&quot;,
      &quot;exception&quot;: &quot;Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException&quot;,
      &quot;file&quot;: &quot;/var/www/vendor_portal/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php&quot;,
      &quot;line&quot;: 117
  }
  </code></pre>
  <p>I've tried many different ways but still keep getting this error. Can someone please help me with this scenario ?</p>