title: Submit Laravel form using JavaScript
body: <p>I have an HTML form that I currently submit using the form action attribute and a php script. The post request is successful, but it reloads the page, and I want to avoid that. The project uses Laravel/Blade PHP templates.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form 
    id=&quot;update-form&quot; 
    method=&quot;post&quot;
    action=&quot;{{ route('update', ['id' =&gt; $user['id']]) }}&quot;
  &gt;
  @csrf
  ...
  &lt;/form&gt;
  
  &lt;button type=&quot;submit&quot; form=&quot;update-form&quot;&gt;Submit&lt;/button&gt;
  </code></pre>
  <p>To prevent page from reloading, I would like to send the post request using JavaScript and use <code>preventDefault()</code>. I tried to use fetch, but as I am not familiar with Laravel I don't understand which parameter I should send. For example, what is the body?</p>
  <p>There are lots of posts on that subject, but most are outdated and result in jQuery solutions, which is not an option for me.</p>
  <p>Here is what I tried:</p>
  <pre class="lang-js prettyprint-override"><code>document.querySelector('#update-form').addEventListener('submit', (e) =&gt; {
    e.preventDefault();
    fetch(&quot;{{ route('update', ['id' =&gt; $user['id']]) }}&quot;, { 
      method: 'post'
    }).then(() =&gt; console.log('success'));
  });
  </code></pre>