title: How return true or false function of data response ajax?
body: <p>I want return true if data is empty or false if data is not empty.If data is empty continue with form action else stay in current page.</p>
  
  <p>Code is:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function error()
      { 
          var response = false;
          $.ajax({
              url: BASE_URL + 'auth/validateForm',
              type: 'POST',
              data: {
                  surname: $("#r-surname").val()
              },
              dataType: "json",
              success: function(data) { 
                  if(data.surname)
                  { 
                      $('#error_surname').html(data.surname);
                      response = false;
                  }else{
                      $('#error_surname').html('');
                      response = true;
                  }
  
              },
              error: function(data) { 
                          return false;
              }
          });
          alert(response);
              return response;
      }
  
  &lt;/script&gt;
  
  &lt;form action="{$BASE_URL}contul-meu" method="post" name="registration" onsubmit="return error()"&gt;
                          &lt;table&gt;                              
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      &lt;label for="r-surname"&gt;Prenume*&lt;/label&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;input type="text" class="text" id="r-surname" name="surname"  value="{$user['surname']}"/&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;&lt;small id="error_surname" class="err"&gt;&lt;/small&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>public function validateForm()
  {
      $surname = $this-&gt;input-&gt;post('surname');
      $data = array();
      if(strip_tags($surname) == '')
      {
          $data['surname'] = 'Prenumele este invalid!';
      }
  
      echo json_encode($data);
  }
  </code></pre>
  
  <p>var response is only false.How make response true if no error?</p>