Answer the question
In order to leave comments, you need to log in
How to determine if JSON has already been loaded?
Made a JSON request. The data has arrived.
But I can't use them outside of $.get ! Why is the alert not displayed?
$(function(){
$.get('file.php', obrabotka,'json');
function obrabotka(data){
var arr = Object.keys(data).map((key) => [key, data[key]] );
};
alert("снаружи"+arr);
});
Answer the question
In order to leave comments, you need to log in
Getting JSON via ajax is an asynchronous operation. JavaScript, on the other hand, is synchronous, so the $.get and alert calls happen instantly one after the other, and only then the obrabotka function is called .
You can only access arr inside the obrabotka function .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question