return answer with json from laravel and access it with jquery

2

Greetings community! I'm doing the following


Of the customer day with Jquery

  

In the next function I get an email and send it with ajax using everything right here   How could I return a json array from the server and access it from JQuery?

  $('#email').focusout(function(event) {
  event.preventDefault();
    $(function() {
          var parametros = {
            "email" :$("#email").val()}
          $.ajax({
               data:  parametros,
               url:   'validar_correo',
               dataType: "json",
               type:  'post',
               beforeSend: function () {
                       $("#respuesta").html("Procesando, espere por favor...");
               },
               success:  function (json) {
                 console.log(json);
                 $("#respuesta").html("");
                  if (json.validar_correo == true) {
                    $("#respuesta").html("El correo ya existe");
                  }
               }
          });
   });
 });

On the server side

  public function validar_correo(){
            $datos =Input::all();
            if (condicion) {
              $response = Response::json(array("validar_correo"=>True));

            }else{
              $response = Response::json(array("validar_correo"=>False));
            }
  }
    
asked by harriroot 09.10.2016 в 05:02
source

1 answer

0
$.ajax({
  method: "POST",
  url: "validar_correo",
  data: { email: $("#email").val()}
})
  .done(function( response ) {
    alert( "Arreglo datos: " + response.data );
  });

// LARAVEL

use App\Mimodelo;


$arreglo = Mimodelo::all();
return \Response::json(['validar_correo' => 'false', 'data' => $arreglo, 'status' => '200'], 200);
    
answered by 09.10.2016 / 11:29
source