title: getting already posted post fields and updating them using jquery
body: <p>I'm working on laravel, want to edit post having multiple fields to edit.
  <strong>I've successfully done this with my post's body field , want to achieve with the other two.</strong></p>
  
  <p>Related <code>controller</code> code:</p>
  
  <pre><code>$post-&gt;body=$data['body'];
  $post-&gt;state = $data['state'];
  $post-&gt;problem_domain = $data['problem_domain'];
  $post-&gt;update();
  return response()-&gt;json(['new_body'=&gt;$post-&gt;body],500);
  </code></pre>
  
  <p><code>blade</code> from where the earlier data needs to be fetched:</p>
  
  <pre><code>&lt;article class="post" data-postid="{{ $post-&gt;id }}"&gt;
      &lt;p&gt; {{ $post-&gt;body }} &lt;/p&gt;
      &lt;p&gt; &lt;b&gt; Region: &lt;/b&gt; {{ $post-&gt;state }} &amp;nbsp &lt;b&gt; Problem Domain: &lt;/b&gt;
      {{ $post-&gt;problem_domain}}&lt;/p&gt;
      &lt;div class="info"&gt;
         posted by &lt;b&gt;{{ $post-&gt;user-&gt;name }}&lt;/b&gt;  on 
         &lt;b&gt;{{ $post-&gt;created_at }}&lt;/b&gt;
      &lt;/div&gt;
      &lt;div class="interaction"&gt;
        &lt;a href="#" class="like"&gt;{{ Auth::user()-&gt;likes()-&gt;where('post_id',$post-&gt;id)-&gt;first() ? Auth::user()-&gt;likes()-&gt;where('post_id',$post-&gt;id)-&gt;first()-&gt;like == 1 ? 'You like this post':'Like':'Like'}} &lt;/a&gt;
        &lt;a href="#" class="like"&gt;{{ Auth::user()-&gt;likes()-&gt;where('post_id',$post-&gt;id)-&gt;first() ? Auth::user()-&gt;likes()-&gt;where('post_id',$post-&gt;id)-&gt;first()-&gt;like == 0 ? 'You don\'t like this post':'Dislike':'Dislike'}}&lt;/a&gt;
        @if(Auth::user() == $post-&gt;user)
          &lt;a href="#" class="edit"  &gt;Edit&lt;/a&gt;
  </code></pre>
  
  <p>and finally my <code>js file</code>,please look at the format for <code>body</code> which is correct and want to do same for other two</p>
  
  <pre><code>var postId=0;
  var postBodyElement=null;
  $('.post').find('.interaction').find('.edit').on('click',function(event){
      event.preventDefault();
      postBodyElement=event.target.parentNode.parentNode.childNodes[1];
      var postBody=postBodyElement.textContent;
      postId=event.target.parentNode.parentNode.dataset['postid'];
      $('#post-body').val(postBody);
      $('#edit-modal').modal();
  });
  $('#modal-save').on('click',function()
      {  
          $.ajax(
              {
              method : 'POST',
              url :  urlEdit,
              data: {body: $('#post-body').val(), state: $('#post-state').val(), 
              problem_domain: $('#post-problem_domain').val(), postId: postId, _token: token}
           })
          .done(function(msg)
               {
                   $(postBodyElement).text(msg['new_body']);
                   $('#edit-modal').modal('hide');
               });
       }
  );
  </code></pre>