I'm building a function that via ajax makes the query a query in the database and via json returns the result. But everything else works I can not use the json object anywhere except inside the function.
I have tried to use global variable declared inside and outside the function, return and nothing is right. follow the code.
var sqls;
function sql(query){
$.ajax({
type: "POST",
url: "php/lookup.php",
dataType: "json",
data: {query: query},
success:function(dados){
sqls = dados;
}
});
return sqls;
};
If I give an alert (sqls.informacao_que_quero); the message appears undefined however if I put the alert inside the sql function it works normally.
I need to access this json anywhere in the script