title: Laravel 5.4: Submit a HTML form and receive a JSON response
body: <p>Question: how can I communicate JSON back from a controller to my html page, and embed the response in my page, instead of destroying the page?</p>
  
  <p>The long story is like this:</p>
  
  <p>Embedded in a quite large html page (created by a view when I open my base URL, say, <a href="http://.../home" rel="nofollow noreferrer">http://.../home</a>) I have a html form. It has some data fields, and the usual "Submit" button.</p>
  
  <pre><code>&lt;form class="form-horizontal" method="POST" action="{{ route('form.user') }}"&gt;
      {{ csrf_field() }}
  
      ... lots of input fields ...
  
      &lt;div class="form-group"&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;
              Submit
          &lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The receiving route ...</p>
  
  <pre><code>Route::post('form/user','ItemController@save')-&gt;name('form.user');
  </code></pre>
  
  <p>And the controller ...</p>
  
  <pre><code>public function save(Request $request) {
  
  ...
  return response()-&gt;json(['status' =&gt; 'Saved successfully']);
  </code></pre>
  
  <p>}</p>
  
  <p>The whole thing works like intended, if I fill the form and hit the "Submit" button, the controller receives all input fields via the $request properties.</p>
  
  <p>The problem arises after the return from the controller, the html is cleared from the browser, and the JSON is displayed.</p>
  
  <p>What I need is receive the JSON and display it in a div of my original html, not replace it.</p>
  
  <p>Question: what do I need to do, how can I hook into the communication to intercept and handle the JSON response, so I can display the response text in my original web page (using JQuery), and not destroy the html?</p>
  
  <p>Thx, Armin.</p>