title: Ajax request keeps returning error function in Laravel
body: <p>Good day guys. In my laravel application I'm trying to check if attendence for a particular <strong>date, subject, grade</strong> exists in my table. If so I have an <code>if statement</code> setup to display desire results based on what is returned.</p>
  
  <p>I'm making the request with ajax but it seems like ajax keeps running the error function and I don't seem to get any error code whatsoever or <code>internal server error(500, 404, 403, etc)</code> In my console the status return is <code>200 ok</code></p>
  
  <p>here is my script:</p>
  
  <pre><code>$(document).on('change', '#subject', function(event) {
    event.preventDefault();
    /* Act on the event */
  
    var subject = $('#subject').val();
    var grade = $('#grade').val();
    var date = $('#date').val();
  
    if (subject != "" &amp;&amp; grade != "") {
      $.ajax({
        url:"/attendence/students",
        method:"GET",
        data:{"subject_id":subject, "grade_id":grade, "date":date},
        dataType:"json",
        success:function(data){
          $("#result").html(data);
        },
        error:function(){
          $("#result").html('There was an error please contact administrator');
        }
      });
    }
  });
  </code></pre>
  
  <p>Here is the controller the request is send to:</p>
  
  <pre><code> public function students(Request $request)
  {
      //
      $grade = Grade::findOrFail($request-&gt;grade_id);
  
      $subject = Subject::findOrFail($request-&gt;subject_id);
  
      $students = Student::where('grade_id', $grade-&gt;id)-&gt;get(['id', 'first_name','middle_name', 'surname', 'grade_id']);
  
      $statuses = Attendence::statuses();
  
      // this check if attendence has been setup for the given date.
      // if so prevent user for enter another date
      $attendenceExists = Attendence::where([
          'grade_id' =&gt; $grade-&gt;id, 
          'subject_id' =&gt; $subject-&gt;id, 
          'date' =&gt; $request-&gt;date
      ])-&gt;first();
  
  
      if ($attendenceExists) {
          return response()-&gt;json('A recorded attendence already exists for the seleced grade and subject!');
      } 
      else {
          return \View::make('attendence.partials.attendence-form')-&gt;with(array(
              'students' =&gt; $students,
              'subject' =&gt; $subject,
              'date' =&gt; $request-&gt;date,
              'statuses' =&gt; $statuses
          ));
      }
  
  }
  </code></pre>
  
  <p>Now, if this code returns true:</p>
  
  <pre><code>// this check if attendence has been setup for the given date.
      // if so prevent user for enter another date
      $attendenceExists = Attendence::where([
          'grade_id' =&gt; $grade-&gt;id, 
          'subject_id' =&gt; $subject-&gt;id, 
          'date' =&gt; $request-&gt;date
      ])-&gt;first();
  
     if ($attendenceExists) {
          return response()-&gt;json('A recorded attendence already exists for the seleced grade and subject!');
      } 
  </code></pre>
  
  <p>The condition here runs and the right result is returned. But my <code>else statement</code> in the above does run but I don't get the right result. This is the result I get:</p>
  
  <blockquote>
    <p>There was an error please contact administrator</p>
  </blockquote>
  
  <p>Which shows that it is this part of the ajax request that is running:</p>
  
  <pre><code>error:function(){
     $("#result").html('There was an error please contact administrator');
  }
  </code></pre>
  
  <p>Surprisingly when I check the console this is what I see:</p>
  
  <p><a href="https://i.stack.imgur.com/PFajB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PFajB.png" alt="enter image description here"></a> </p>
  
  <p>Which is exactly what I want but ajax is return otherwise. Am I doing something wrong?</p>