1
I am building a function that via ajax queries a query in the database and via json returns the result. But everything works but I can’t use the json object anywhere else except within the function.
I have tried to use declared global variable in and out of function, Return and nothing right. follows 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 Alert inside the sql function works normally.
need to have access to this json anywhere in the script
There’s enough material in the community about it!
– Maurivan
See if this question helps you! I even answered it too! http://answall.com/questions/182500/return-true-ou-false-no-success-do-jquery
– Maurivan