This question has already been answered:
There is an ajax query, how to get the result from it and assign it to the variable queryResult, then the queryResult variable should be checked and if something is wrong with its value, you need to exit addPartition ():
function addPartition(){ var queryResult; $.post('controllers/handlerPartition.php', {'isExistPartition': true, 'partitionName': $('#modal_win1_partition_name').val()}, function (result) { return result; //Как получить это значение из вне? } ); if (queryResult === 'false') return; } I tried this:
function addPartition(){ var queryResult; $.post('controllers/handlerPartition.php', {'isExistPartition': true, 'partitionName': $('#modal_win1_partition_name').val()}, function (result) { queryResult = result; //Присвоение внешней переменой } ); alert(typeof queryResult); //undefined if (queryResult === 'false') return; } But the value of queryResult is not certain. I understand this because of the asynchrony?
resultwill not be assigned to aqueryResultbefore thefunction (result) { ... }called. UsequeryResultinside callback'a. - Igorfunction (result) { ... }function isaddPartition(){ ... }, theaddPartition(){ ... }functionaddPartition(){ ... }work long ago. - Igor