0
I am currently using ajax making several different requests for queries.
Ex:
$.ajax({
method: "POST",
url: "getData.php",
data: { nome:nome, endereco: endereco }
})
.done(function( data ) {
var dados = data;
//aqui faço todas validações que preciso
});
However, when I need to do a new validation differently, out of return . done I don’t have access to 'data' from data
.
I wondered if I could somehow make this requisition ajax and store the data to not need to each need to validate a new request.
The block
.done()
is executed after the request when no error occurs. If the goal is to validate something before request, implement a blockbeforeSend
. Details in the ajax documentation: http://api.jquery.com/jquery.ajax/– LipESprY
right, see what I need would be something like storing what comes from the return of
ajax
in a variable and access it outside the scope.done()
. Ex: in the above ajax I have variable data, after closing the done tag I can no longer access that variable. If I have it I need more below validate a new example field compareif($("#enderecob") == dados.endereco) { // tratar aqui }
, this out of done, it doesn’t work, there’s some way to do it?– JB_
It has as if that if is inside a function.
– Sam
Got it, is that I haven’t seen any such example, and in my case today every time I need a PHP information in JS I’m making a new ajax request to get the data to handle the information. I looked for some information in this sense and found something that ajax and assicronomo and does not allow to work globally only within the scope.
– JB_