title: Ajax script to update record does not work, Laravel
body: <p>I wrote a small script that updates the information on the page when editing. Everything basically works as it should, but I just can’t update the image. I don’t understand what the matter is. Without a script, with a page reload, everything works as it should.</p>
  <p>Ajax script</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  
      $(&quot;document&quot;).ready(function() {
          $(&quot;#editPostButton{{$post-&gt;id}}&quot;).click(function() {
  
              var formData = $(&quot;#EditPostForm{{$post-&gt;id}}&quot;).serialize();
  
              $.ajax({
                  url: &quot;{{route('editPost', ['id' =&gt; $user-&gt;id, 'postId' =&gt; $post-&gt;id])}}&quot;,
                  type: &quot;POST&quot;,
                  data: formData,
                  success: function(data) {
                      $(&quot;#textpostdata{{$post-&gt;id}}&quot;).html($(data).find(&quot;#textpostdata{{$post-&gt;id}}&quot;).html());
                      $(&quot;#closeButton{{$post-&gt;id}}&quot;).click();
                  }
             });
  
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  <p>My Controller</p>
  <pre><code>public function editPost(Request $request, $id, $postId) {
  
      $validator  = $this-&gt;validate($request,[
          'title' =&gt; 'max:100',
          'message' =&gt; 'max:5000',
          'img' =&gt; 'mimes:jpeg,png,gif,jpg|max:5000',
          'videoPost' =&gt; 'max:100'
      ]);
  
      if($validator) {
          $user = User::find($id);
          if(!$user &amp;&amp; $user != Auth::user()-&gt;id) {
              return abort(404);
          }
          $post = Profile::find($postId);
          if(!$post) {
              return abort(404);
          }
  
          $post-&gt;user_id = Auth::user()-&gt;id;
          $post-&gt;title = $request-&gt;title;
          $post-&gt;message = $request-&gt;message;
          $post-&gt;videoPost = str_replace('watch?v=', 'embed/', $request-&gt;videoPost);
  
          if($request-&gt;file('img')) {
              $path = Storage::putFile('public/'.Auth::user()-&gt;id.'/post', $request-&gt;file('img'));
              $url = Storage::url($path);
              $post-&gt;img = $url;
          }
  
          $post-&gt;update();
  
          return redirect()-&gt;back();
      }
  }
  </code></pre>
  <p>And update form</p>
  <pre><code>&lt;form action=&quot;{{route('editPost', ['id' =&gt; $user-&gt;id, 'postId' =&gt; $post-&gt;id])}}&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; id=&quot;EditPostForm{{$post-&gt;id}}&quot; name=&quot;postForm&quot;&gt;
       @csrf @method('PATCH')
       &lt;div class=&quot;form-group&quot;&gt;
           &lt;textarea maxlength=&quot;100&quot; name=&quot;title&quot; class=&quot;form-control&quot; rows=&quot;1&quot;&gt;{{$post-&gt;title}}&lt;/textarea&gt;
       &lt;/div&gt;
       &lt;div class=&quot;form-group&quot;&gt;
           &lt;textarea id=&quot;message&quot; maxlength=&quot;5000&quot; name=&quot;message&quot; class=&quot;form-control&quot; rows=&quot;10&quot;&gt;{{$post-&gt;message}}&lt;/textarea&gt;
       &lt;/div&gt;
       &lt;div class=&quot;form-group&quot;&gt;
           &lt;textarea maxlength=&quot;100&quot; class=&quot;form-control mt-1&quot; id=&quot;videoPost&quot; name=&quot;videoPost&quot; cols=&quot;100&quot; rows=&quot;1&quot;&gt;{{$post-&gt;videoPost}}&lt;/textarea&gt;
       &lt;/div&gt;
       &lt;h6&gt;Current image&lt;/h6&gt;
       &lt;img src=&quot;{{$post-&gt;img}}&quot; class=&quot;img-fluid mb-2&quot; width=&quot;230&quot;&gt;
       &lt;div class=&quot;form-group&quot;&gt;
           &lt;input type=&quot;file&quot; id=&quot;img&quot; name=&quot;img&quot; accept=&quot;image/*&quot;&gt;
       &lt;/div&gt;
  
       &lt;button type=&quot;button&quot; class=&quot;btn btn-sm btn-primary&quot; id=&quot;editPostButton{{$post-&gt;id}}&quot;&gt;Edit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>