This question has already been answered:
Good day. There is a function that loads data using Ajax request to the database data by user Id
function getDialogToId(idVk){ var pageRez='0'; $.ajax({ url: 'http://site.ru/ajax/ids.php', type: 'POST', data: 'func=getDialogToId' + '&idVk=' + idVk, dataType: 'json', }).done(function(rez) { pageRez = rez.page; }).fail(function() { alert('ОШИБКА, что-то не так'); }); return pageRez; } But the problem is that as soon as I call it in a loop, the variables come undefined, tell me what's the matter? Why doesn't the function wait for the result that should come in the Ajax request, but immediately returns a non-defined variable? and how can this be fixed? Thank.
Here is the calling code:
getDialogToId('5093649');
undefined? Add code to the question - ThisManpromiseAll- ThisMan