title: How to make jQuery alert if PHP response is equal to something
body: <p>I have this jQuery script:</p>
  
  <pre><code>$(document).ready(function(){
      $('#submitNewExam').click(function(e){
          e.preventDefault();
          var examName = $('#newExam').val();
          if ($.trim(newExam) != ''){
              $.post('functions/addExam.php', { newExam: examName }, function(data){
                  console.log(data);
                  if(data =='error'){
                      $('#notify').html(data);
                      $('.alert').toggle();
                  }
              });
          }
          $('.add').toggle();
      });
      });
  </code></pre>
  
  <p>and this PHP:</p>
  
  <pre><code>if(isset($_POST['newExam'])){
      if(preg_match('/(&lt;|&gt;|"|%3c|%3e|%22)/', $_POST['newExam'])){
          $a = 'error';
          echo json_encode($a);
      } else {
          echo "something";
      }
  }   
  </code></pre>
  
  <p>I'm able to output the response of PHP, what I'm not able to do is to make jQuery read that response and do something if the response in my example is equal to error. I have tried to encode the response in JSON and just to echo the response as a string, but none of those is working. In the <code>console.log</code> I can see the response but jQuery is doing nothing. </p>