У меня есть тесно связанный javascript, где есть ряд проверок if-else и многократные вызовы ajax. Ajax-вызовы имеют вложенный тип. Моя проблема в том, что я нахожусь в глубоко вложенной функции ajax, вызываемой и хочу изящно выбраться оттуда.
Фрагмент кода.
function showSubscriptionLightBox() {
$.get("/ajax/get_subscription_lightbox_content.php?feed_id=" + feedid, function(data) {
//Work on the data we receive... and check whether user is logged in.
if(userLoggedIn) {
//Make one more ajax call
$.get("/ajax/is_user_subscribed.php?feed_id=" + feedid, function(data) {
//Work on data again.... and check if user is subscribed.
if(userSubscribed) {
//Then there is popup which comes up, a part of same page and it has a button name "task".
document.getElementById('task').onclick = function() {
if(document.getElementById('email_mode').checked) {
$.ajax({
url : "ajax/is_user_email_verified.php?user_id="+userID,
success : function(data) {
if(!data)
return;
var response;
response = eval("response = " + data);
if(!response)
return;
if(response['email_status'] == 0) {
//Exit from here
}}}
......
другая часть кода ..
Я хочу изящно выйти из JavaScript, когда ответ ['email_status'] == 0
Скажите, пожалуйста, как это сделать?
Я попробовал оператор return, но он перенес меня в функцию включения, а не вне скрипта.
Спасибо
Amit