Sending data to Controller via Ajax LARAVEl [closed]

0

I have a project in which I have to send the CPF of a patient to a method in the controller in order to search within this method and already return the search value to the view, but I am not able to send those values to the view.

Update I am already getting access to the controller and return the object to ajax but I am still not able to access it in ajax. no error appears and I can check on the network that the controller method is returning the data correctly. follow new updated code:

controller

public function verificarCadastro (Request $request){

     return \Response::json($this->paciente->where('cpf',$request->cpf)->get());        

}

ajax na view

    function buscarCpf() {

    cpf = $('#cpfBusca').val();



    $.ajax({

        url: window.location.href+"/verificar-cadastro", 
        type: "POST",
        data: {"cpf": cpf,"_token":"{{csrf_token()}}" },
        cache: false,
        processData: true,
        dateType:'json',
        sucess: function(data) {

            if(data.cpf != null)
                console.log(data.cpf);

        },
        erro: function(data){

            console.log(data);
        }       

    });
              //window.location.href = caminho;


     };

Return on the network

    
asked by anonymous 10.09.2017 / 22:00

1 answer

1

PHP is back-end, it processes and generates pages, whether HTML, txt, or image, etc.

The variable data is JavaScript and in turn is rendered on the front end, long after the HTML page was generated by PHP + Laravel, you will not be able to play the variable data "has already been processed!" :

"{{ URL::route('hospedagem.registrar',data) }}";

That is, you can not pass a JavaScript variable directly to PHP, as I explained in

10.09.2017 / 23:06