0
I have a project in which I have to send a patient’s CPF to a method in the controller in order to do a search within this method and already return the value of the search to the view , however I am not able to send these values to the view.
Updating
I am already able to access the controller and return the object to the ajax but I am not yet able to access the ajax. no error appears and I can verify on the network that the controller method is returning the data correctly.
follows new updated code:
controller
public function verificarCadastro (Request $request){
return \Response::json($this->paciente->where('cpf',$request->cpf)->get());
}
ajax in 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 that is coming on the network
how can I be solving this case then?
– Márcio César
@Márciocésar you can use Session in the back-end (in Laravel) or querystring in
window.location
, but it will depend on what your routes do, there’s no way to give a precise answer because I have no idea what your code is.– Guilherme Nascimento
edited the code I’d like you to take a look at
– Márcio César
@Márciocésar you only changed the Javascript part and posted only part of the controller, in this case the
verificarCadastro
, the way this I can’t even know where to start, I need to understand where you want to send JSON data. Understand?– Guilherme Nascimento
then I am making a check to know if the registration exists in the case if it returns the json in sucess: from ajax and I can at least run the console.log() on my screen with the data you are asking would already cure my doubt, however it does not return anything there in sucess and not in error, but the data is being sent by the controller as you can check on the network I put in the image
– Márcio César
@Márciocésar I understand, but the
window.location
? Please read this link https://answall.com/help/mcve. and try to revise the question, because you have changed the context of the question and still have not explained well what you have done, I really want to help, but there is no way to understand it. I recommend that you follow the recommendations and I will surely be able to help you.– Guilherme Nascimento
I was able to solve the problem by making a simple correction in the code the name sucess was wrong : the correct is Success.
– Márcio César