title: Ajax in Cakephp 2.x
body: <p>I have a problem, i need to use, ajax in a form, in my page i have to change the color of a label after i search if a data is in a data base, if the data exist i must change the color of the label to red, if not i have to changed to green, i know how to use this in pure php, but i don´t know how to do that in cakephp, if i am not wrong in pure php this is the forme to do it:</p>
  
  <p>View</p>
  
  <pre><code>&lt;form action="prueba.php" method="post"&gt;
  &lt;input type="text" id="txt_prueba" class="validador" /&gt;
  &lt;submit value="enviar"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>View in Cake</p>
  
  <pre><code>&lt;?php
    echo $this-&gt;Form-&gt;create('Prueba', array('url' =&gt; 'prueba.php', 'type' =&gt; 'post'));
  
           echo $this-&gt;Form-&gt;input('textoPrueba', array('label' =&gt; false,
              'class' =&gt; 'validador'));
     echo $this-&gt;Form-&gt;end(); ?&gt;
  </code></pre>
  
  <p>Script </p>
  
  <pre><code>    $(".validador").on('keyup keypress blur change', function (tecla) {
        $.ajax({
            method: "POST",
            url: "algun.php",
            data: { 
             name: $("#txt_prueba").val();
            }
        })
        .done(function( msg ) {
             if (msg=="Yes"){
                    $("#txt_prueba").css('background-color', 'red');
              } else{
                    $("#txt_prueba").css('background-color', 'green');
              }
         });
  });
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>require('conexion.php');
  
  $consulta = $_POST['name'];
  
  if (isset($consulta)) {
  
      $consulta = mysqli_query($conexion, "SELECT * FROM tabla1
      WHERE nombre LIKE '$consulta'");
  
     $filas = mysqli_num_rows($consulta);
  
     if ($filas === 0) {
              echo 'Not';
  
     }else {
       echo 'Yes';
     }
  };
  </code></pre>