2

Currently i am working on twitter bootstrap form wizard in which next button click onNext event is fire in which i fire ajax call.

Problem: i take one java script variable rsult and set it false when ajax return success data i want to update rsult variable but before success data is come other code is start to execute because of asynchronous nature of ajax.

What i want to do ? i want update rsult variable after success is coming with asynchronous call

My Code :

onNext: function (tab, navigation, index) {
if (form.valid() == false) {
    return false;
}
else if (index == 1) {
    var rsult = false;
    $.ajax({
        url: '/abc/abc',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(TFN),
        //async:false,
        success: function (data) {
            debugger;
            showMessage(data.type, data.message);
            if (data.type != "error") {
                rsult = true;
            }
            $('.nloader').hide();
        },
        error: function (xhr, ajaxOptions, thrownError) {
            showMessage("error", xhr.responseText);
        }
    });
} else {
    rsult = false;
    doError('Invalid TFN, check the digits.');
    $('.nloader').hide();
}
if (!rsult) {
    return rsult;
}
handleTitle(tab, navigation, index);
}

Note: i don't want to write async:false because it freeze whole browser

Shah Niral
  • 121
  • 11

0 Answers0