title: Access JSON Ajax Response data
body: <p>I have added a property to a JSON data but I cannot access the data on JS it does not show. I am not new to Ajax and JSON but it is a apparent that I still have gaps in my knowledge when it comes to Ajax. Please help me understand how i can append data to my Ajax response. </p>
  
  <p>I have this in a PHP controller class:</p>
  
  <pre><code>$x = '5';
  
  if($request-&gt;ajax()){
      return response()-&gt;json([
          'total_questions' =&gt; $x,
          'responseText' =&gt; $e-&gt;getMessage(), 
      ], 500);
  }
  </code></pre>
  
  <p>I want to access the total_questions property with JS/JQuery..</p>
  
  <p>My JS AJAX callback is here:
   console.log('errors -> ', data.total_questions); - returns undefined </p>
  
  <pre><code>$.ajax({
  
      type:"POST",
      url: APP_URL+"selfEvaluation/save",
      data:$(this).serialize(),
      dataType: 'json',
      success: function(data){
          console.log(data);
      },
      error: function(data){
          var errors = data.responseJSON;
          console.log('data -&gt; ', data);
          console.log('errors -&gt; ', data.total_questions);
  
          if(data.status == 422){
              // alert('422');
          }
      }
  });
  </code></pre>
  
  <p>This is my console result 
  <a href="https://i.stack.imgur.com/cb780.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cb780.png" alt="enter image description here"></a></p>