Goog Morning, everyone.
I still have some problems trying to use arrays which were gotten from php. The problem is that when I got an array , I can not use it out of the "success function". So this is what is happening.
I create a var called "langs" to save array's information:
var langs=[];
Then, when I use console.log for print array's information INSIDE function success, my code seems like this:
$.ajax({
type: 'POST',
url: '/ws/languagesForJs',
dataType: 'json',
success: function(result) {
langs=result;
console.log(result)
},
});
It works Great!! I can see the array's information. It looks like this:
Object {es: Object, en: Object}
en: Object
lang_ext_name: "en_US"
lang_id: 2
lang_iso: "en"
lang_name: "Inglés"
lang_url: "en"
__proto__: Object
es: Object
lang_ext_name: "es_PE"
lang_id: 1
lang_iso: "es"
lang_name: "Español"
lang_url: "es"
__proto__: Object
__proto__: Object
HOWEVER,When I use console.log for print array's information OUTSIDE function success:
$.ajax({
type: 'POST',
url: '/ws/languagesForJs',
dataType: 'json',
success: function(result) {
langs=result;
},
});
console.log(result)
It returns just;
[]
Sincerely, I do not know why is it happens. Maybe I'm missing some function's theory or something. I've looked for info on the web;however, it seems that no one needs an array outside success functions. I haven't found any information about it.
I hope someone can help me. Thanks
Btw: Sorry for my bad english. It is not my mother language.
resultis a local variable to the success function, it cannot be referenced outside of that function. Are you declaring result above the AJAX call as well?